salesforce / sfdx-lwc-jest

Run Jest against LWC components in SFDX workspace environment
MIT License
164 stars 81 forks source link

Support Jest 29 and use of new conditional directives support for elements other than template #319

Closed manish3344 closed 1 year ago

manish3344 commented 1 year ago

Description

Issue 1

Unable to run my tests with Jest v29 and latest v2.0.0 version of sfdx-lwc-jest (attached the error below), The only workaround is to use v1.1.3 where the jest was upgraded to v29 but later it was removed in v1.1.4 because of a breaking change?

The main reason for my upgrade is because I want the tests to recognize the new conditional directives lwc:if,lwc:else as the older versions doesn't recognize them and fail the tests.

Steps to Reproduce

# Command to repro
> sfdx-lwc-jest -- --reporters=default --silent XXXX

 FAIL  test/main/default/lwc/XXXX/__tests__/XXXX.test.js
  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')

      at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:63:28)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        26.092 s

Issue 2

The other thing i noticed with v1.1.3 when I use the conditional directives on HTML elements or custom elements instead of template throws following error even though deploy was successful and working, I found this documentation which says we can use the new conditional directives on template and some HTML elements too. Shouldn't that be supported too on other elements or should we keep using template?

 ● Test suite failed to run
    thrown: [Error: LWC1127: Invalid directive "lwc:else" on element <div>.]
    thrown: [Error: LWC1127: Invalid directive "lwc:else" on element <p>.]
    thrown: [Error: LWC1127: Invalid directive "lwc:if" on element <c-some-custom-lwc>.] 

Expected Results

Issue 1: Make @salesforce/sfdx-lwc-jest work with Jest v29

Issue 2: Support use of new conditional directives on HTML and custom elements.

Actual Results

Unit tests fail.

Version

nolanlawson commented 1 year ago

W-13720532

yippie commented 1 year ago

I can't believe Jest STILL hasn't been updated. Jest 27 doesn't support node 18 yet and node 16 is EOL in just a few months.