Open RemyVULTAGGIO opened 2 years ago
In addition, when sfdx-lwc-jest is installed globally, the "jest.config.js" file is not correctly interpreted.
sfdx-lwc-jest
Error: Cannot find module '@salesforce/sfdx-lwc-jest/config' Require stack:
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.