You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test Suites: 2 passed, 2 total
Tests: 17 passed, 17 total
Snapshots: 0 total
Time: 2.45 s
Ran all test suites.
Actual Results
sfdx-lwc-jest
FAIL force-app/lwc/tests/myComponentA.test.js
● c-my-component-a › myMethod @wire › renders three toasts when data returned
TypeError: myMethod.emit is not a function
57 |
58 | // Emit data from @wire
> 59 | myMethod.emit( mockGetCheckMessages );
| ^
60 |
61 | // Wait for any asynchronous DOM updates
62 | await flushPromises();
at Object.emit (force-app/lwc/__tests__/myComponentA.test.js:59:30)
● c-my-component-a › is accessible when data is returned
TypeError: myMethod.emit is not a function
101 | // Wait for any asynchronous DOM updates
102 | await flushPromises();
at Object.error (force-app/lwc/__tests__/myComponentA.test.js:99:26)
PASS force-app/lwc/tests/myComponentB.test.js
Test Suites: 1 failed, 1 passed, 2 total
Tests: 3 failed, 14 passed, 17 total
Snapshots: 0 total
Time: 2.445 s
Ran all test suites.
Version
node --version
v16.17.0
sfdx version
sfdx-cli/7.173.0 win32-x64 node-v16.17.1
I did several tests. When sfdx-lwc-jest is installed locally (e.g. : npm install @salesforce/sfdx-lwc-jest --local --omit=dev) everything works fine.
Very important : I don't want to install sfdx-lwc-jest on each sfdx project. Or, at least, I want to install locally as few modules as possible if none is not an option.
Thanks in advance for your time & help.
The text was updated successfully, but these errors were encountered:
C:\Users\aUser\AppData\Roaming\npm\node_modules@salesforce\sfdx-lwc-jest\node_modules\jest\bin\jest.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
at Function.Module._load (node:internal/modules/cjs/loader:804:27)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\Lokahi\sources\lokahi-isv\jest.config.js:1:24)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
Here too, when sfdx-lwc-jest is installed locally everything works fine.
Description
When sfdx-lwc-jest is installed globally, tests run with mocked Apex Method are failing
Steps to Reproduce
From the root of a SFDX Project with LWC tests using mocked Apex Method
example of mocking code in one of the lwc/tests/*.test.js files :
// Mock myMethod Apex wire adapter
jest.mock(
'@salesforce/apex/myController.myMethod',
() => {
const {
createApexTestWireAdapter
} = require( '@salesforce/sfdx-lwc-jest' );
return {
default: createApexTestWireAdapter( jest.fn() )
};
},
{ virtual: true }
);
If sfdx-lwc-jest is installed globally
example of installation command-line :
npm install @salesforce/sfdx-lwc-jest --location=global --omit=dev
When running the command-line "sfdx-lwc-jest", tests with mocked Apex Method are failing.
Expected Results
PASS force-app/lwc/tests/myComponentA.test.js
PASS force-app/lwc/tests/myComponentB.test.js
Test Suites: 2 passed, 2 total
Tests: 17 passed, 17 total
Snapshots: 0 total
Time: 2.45 s
Ran all test suites.
Actual Results
FAIL force-app/lwc/tests/myComponentA.test.js
● c-my-component-a › myMethod @wire › renders three toasts when data returned
● c-my-component-a › is accessible when data is returned
PASS force-app/lwc/tests/myComponentB.test.js
Test Suites: 1 failed, 1 passed, 2 total
Tests: 3 failed, 14 passed, 17 total
Snapshots: 0 total
Time: 2.445 s
Ran all test suites.
Version
node --version
v16.17.0
sfdx version
sfdx-cli/7.173.0 win32-x64 node-v16.17.1
sfdx-lwc-jest --version
1.1.3
@renatoliveira already mentioned this "global install issue" in #76
I did several tests. When sfdx-lwc-jest is installed locally (e.g. : npm install @salesforce/sfdx-lwc-jest --local --omit=dev) everything works fine.
Very important : I don't want to install sfdx-lwc-jest on each sfdx project. Or, at least, I want to install locally as few modules as possible if none is not an option.
Thanks in advance for your time & help.
The text was updated successfully, but these errors were encountered: