Questions tagged [lwc-jest]

jest library is used to write unit tests for the front-end JavaScript. This is used in conjunction with LWC to check our front-end modules.

Filter by
Sorted by
Tagged with
0
votes
0answers
35 views

Cannot find module 'lightning/flowSupport' from 'force-app/main/default/lwc/lwcomponent/__test__/lwcomponent.test.js'

Getting below error on import {FlowNavigationNextEvent} from 'lightning/flowSupport'; in jest test file. Cannot find module 'lightning/flowSupport' from 'force-app/main/default/lwc/lwcomponent/test/...
1
vote
1answer
57 views

Unable to run a LWC Jest test for a custom LWC that uses lightning-quick-action-panel or CloseActionScreenEvent

I get this error: Cannot find module 'lightning/quickActionPanel' when running this Jest test: import { createElement } from 'lwc'; import DuplicateScreenAction from 'c/duplicateScreenAction'; let ...
1
vote
1answer
20 views

lwc-oss lightning-base-components jest tests

I am working on an lwc-oss project and found reference to lightning-base-components npm package in a salesforce blog post. https://developer.salesforce.com/blogs/2020/12/build-connected-apps-anywhere-...
0
votes
1answer
51 views

How to get Jest test suite to cover Leaflet Map initialization code?

I'am using a leaflet map in my LWC and it works perfectly fine. However, when I run the test suite for this component using this command test:unit:coverage, I can see that the test script is stuck at ...
1
vote
0answers
28 views

LWC JEST test for API callouts

I want to write JEST test for the following component: // JS file: HTTPCalloutInLWC.js import { LightningElement, track} from 'lwc'; // importing apex class to make callout import getCurrencyData ...
0
votes
0answers
27 views

The “path” argument must be of type string. Received an instance of Object

Got this error while running the following command in jenkinsfile. npm run test:unit:coverage, It runs fine locally on my project. + npm run test:unit:coverage > salesforce-app@1.0.0 test:unit:...
0
votes
0answers
26 views

LWC unit testing, Dynamic row level actions tests

I implemented dynamic row level action as mentioned in documentation getRowActions (row, doneCallback) { const actions = []; if (row['status'] == 'Active') { ...
3
votes
0answers
56 views

What is a typical JavaScript code coverage for LWCs (Lightning Web Components) that are adequately tested via JEST?

I know this might get closed as being a matter of opinion, but as long as those opinions are based on actual experience, such answers are valuable to me, particularly if they are somewhat consistent. ...
3
votes
1answer
118 views

Deploy deletes all JEST Tests?

I just upgraded VS Code (sfdx upgrade). Now when I deploy my project: sfdx force:source:deploy -x .\manifest\package.xml --verbose All of the JEST test files are magically deleted from my local copy! ...
1
vote
0answers
48 views

With LWC Jest, how to mock custom components

I'm trying to unit test my LWC which has another custom component as child. I tried to use the steps describe in this post : import { createElement } from 'lwc'; import EfxProjectReport from 'c/...
1
vote
0answers
204 views

JEST Not Supporting Optional Chaining Operator

I am using the optional chaining operator in one of my LWC components -- running in VS Code with the canonical Salesforce setup. All vanilla. Here is the line of code and the error when I run a JEST ...
0
votes
0answers
24 views

JEST Test Result Varies by User

We have a JEST test for an LWC in our managed package that runs without error for one user in VS Code, but runs with two errors for another user. The test and underlying code are identical for both ...
1
vote
0answers
35 views

How to JEST test a lightning-input of type “file”

I have an LWC that updloads a file: <lightning-input type="file" label={label.AttachInvoice} accept="image/png, image/jpg, image/gif, application/pdf" onchange={...
4
votes
1answer
79 views

How to Mock loadScript in JEST

I have an LWC that loads two external js libraries: import { api, LightningElement } from 'lwc'; import { loadScript } from 'lightning/platformResourceLoader'; import LightningUtil from 'c/...
1
vote
1answer
128 views

LWC + Jest: Assert about what happens before a wire adapter returns data

I have a LWC with a wired function hooked up to the getFiles method in an Apex class, like this: myLwc.html <template> <template if:true={showSpinner}> <lightning-spinner ...
0
votes
1answer
63 views

Not able to access LWC decorator in Jest test JS file?

import {createElement} from 'lwc'; import NewCmp from 'c/newCmp'; describe('c-new-cmp',() => { it('Test New cmp page', () => { const comp = createElement('c-new-cmp',{ ...
2
votes
0answers
46 views

How to Mock getRecordNotifyChange

How exactly do we mock getRecordNotifyChange in a JEST test? I cannot find an example anywhere.
1
vote
1answer
108 views

Can we overwrite mocked values returned in LWC Jest?

I am mocking the values in a custom label using this from https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.unit_testing_using_jest_patterns import myImport from '@...
4
votes
1answer
333 views

lwc jest event.detail.value doesn't seem to work very well with jest test

On lightning-input and lightning-combobox, if we use event.target.value in the on change event, it works fine with the jest test. However, when we use event.detail.value in the on change event, the ...
2
votes
1answer
246 views

LWC jest issue with getRecordNotifyChange - TypeError: (0 , _uiRecordApi.getRecordNotifyChange) is not a function

I am using 'getRecordNotifyChange'https://developer.salesforce.com/docs/component-library/documentation/en/lwc/reference_get_record_notify in a "Modify" LWC component, to flag a record as ...
3
votes
1answer
144 views

lwc jest: when I have an apex callout inside the subscriber method, everything is executed in correct sequence but the result is still not quite well

In order to fully explain what I mean here, I have a proof of concept small component written. Although the loading element is already set to be false according to console.log and in the correct ...
4
votes
1answer
340 views

LWC Jest: is the subscription part code executed in jest function?

When I read the sample code in lwc-recipes, it gives me a feeling that in side Promise().resolve().then() in jest method, the subscription of the published message should be received. However, our ...
0
votes
0answers
41 views

Wire methods calling again but getLastConfig() is not updated

Currency I am trying to write the jest for wire method. Here my wire method is call twice because it's parameter value getting change in the middle. When I am trying to assert in jest by ...
1
vote
0answers
55 views

issue in jest test

I am writing a jest for the component and and getting below error in the event: ABS.dispatchEvent(new CustomEvent('click')); error i am getting : TypeError: function xyz() {return mockConstructor....
1
vote
0answers
48 views

Expect() assertion for modal pop up in lwc test

I have an lwc component which is used for file uploading purposes. Below is the code related to modal pop up from html mark up of the component <template if:true={isModalOpen}> <c-...
1
vote
1answer
352 views

Unable to test variable value with Wire in jest

I am trying to read simple users list with wire method. However, I'm unable to test the variable value in jest promise, is there anything wrong with my code/understanding? LWC - @wire(getUsers) ...
3
votes
1answer
648 views

event.dataTransfer is getting undefined in JEST for dragstart

I'm trying to implement Jest tests for a module(to reorder data table rows). However, I'm unable to mimic the dragstart event. Can anyone help me to achieve the same behavior - Here is the function ...
4
votes
1answer
951 views

Jest LWC, How to test the callback function of a registerListener?

I have a LWC component which performs multiple operations in connectedCallback(), one of them is a registerListener which calls an apex method which updates a record in the DB. Here is my question: ...
3
votes
1answer
546 views

sfdx-lwc-jest' is not recognized as an internal or external command

I am trying to run LWC Jest test, While i'm run this command:"sfdx force:lightning:lwc:test:run" I am getting this error: 'sfdx-lwc-jest' is not recognized as an internal or external command,...
0
votes
0answers
64 views

Error for import not found in JEST test

I am trying to learn jest but , one thing is stopping me and i am not able to resolve. I have below code in my LWC : import testPermission from '@salesforce/customPermission/VS_Ut_li'; get testTab() {...
1
vote
1answer
166 views

DOM is not cleared between tests in lwc-jest

For some reason DOM is not cleared between lwc jest tests (I think). What I want to test that page renders with lightning-input disabled by default and after button click it's enabled. Test pass ...