Skip to content

Commit

Permalink
fix: apex automock should return a resolved promise (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodarove committed Jun 24, 2021
1 parent 0857e58 commit 544f95a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
'use strict';

const path = require('path');

module.exports = {
moduleFileExtensions: ['js', 'html'],
transform: {
'^.+\\.(js|html|css)$': require.resolve('@lwc/jest-transformer'),
},
resolver: path.resolve(__dirname, './src/resolver.js'),
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
snapshotSerializers: [require.resolve('@lwc/jest-serializer')],
};
18 changes: 18 additions & 0 deletions src/apex-stubs/method/__tests__/apex-method.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import method from '../method';

describe('apex resources', () => {
it('should return a resolved promise when apex method is invoked imperatively', () => {
let resolved = false;
method().then(() => (resolved = true));

return Promise.resolve().then(() => {
expect(resolved).toBe(true);
});
});
});
2 changes: 1 addition & 1 deletion src/apex-stubs/method/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*/
import { createApexTestWireAdapter } from '@salesforce/wire-service-jest-util';

export default createApexTestWireAdapter(jest.fn());
export default createApexTestWireAdapter(jest.fn().mockImplementation(() => Promise.resolve()));

0 comments on commit 544f95a

Please sign in to comment.