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
2
votes
1answer
55 views

How to get code coverage report for LWC unit tests with JEST?

I was working on the unit test setup for Lightning Web Components with Jest and tried to figure out how to get a code coverage report but found nothing in the Docs. By running: sfdx-lwc-jest --...
0
votes
0answers
20 views

Write JEST case for LWC component with nested imperative calls

I am passing the data in .mockResolvedValue() method and it is working as expected by providing the correct result. Example : getDataFromApex({accountId : this.accountId}) .then((result) => ...
0
votes
1answer
60 views

registerApexTestWireAdapter is deprecated when working through trailhead Lightning Web Components Tests

I have been working through trailhead from link below https://trailhead.salesforce.com/en/content/learn/modules/test-lightning-web-components and noticed I got a console.warn error console.warn ...
0
votes
0answers
30 views

LWC - registerTestWireAdapter for lightning/navigation with imperative call from wired fails

Let's say we have @wire (CurrentPageReference) getStateParameters(pageRef) { if (pageRef) { /// some statements here this.setSomeData(); } } setSomeData() { getCardData({ ...
1
vote
1answer
78 views

I want to cover the onMouseover event in JavaScript by writing JEST test case in LWC

I want to cover the Jest test for onmouseover event for this .tried with few approrch ,seems like its not working. <template> <div class="consumer-container" if:true={showFlags}&...
0
votes
0answers
18 views

Accessing attribute value in LWC jest shadow dom

I am passing a data to child components like so: componentToTest.js: export default class ComponentToTest extends NavigationMixin(LightningElement) { columns = [ { label: ...
0
votes
0answers
11 views

Jest Mock deleteRecord to throw error

Is it possible to mock uiRecordApi deleteRecord to throw error? it("should show error toast when delete record method throws error", () => { const element = createElement("c-...
4
votes
1answer
115 views

Jest Tests for KeyPress Event

I am trying to step up my Jest skills and working through Wes Boss classic 30 Vanilla JS projects in 30 Days. I thought I would do them all in LWCs with Jest for a challenge. I built my Drum Kit and ...
0
votes
1answer
72 views

LWC jest mocking '@salesforce/apex/refreshApex' problem

I'm trying to get my arms around testing LWC. I'm trying to test a button click that calls some Apex, then calls 'refreshApex' and then throws a success toast. It seems I'm mocking my own custom Apex ...
1
vote
1answer
61 views

How can I export an LWC function that's declared within a constructor?

I have a function that is declared within my default class (constructor) that I would like to export to a Jest test suite. Is this possible? testLWC.js import { LightningElement } from 'lwc'; export ...
2
votes
1answer
119 views

Having issue with jest test for Lightning Quick action and CloseActionScreenEvent

We have a lightning web component which uses lightning quick action tag and this line in js file: import { CloseActionScreenEvent } from "lightning/actions"; And when I run jest test I have ...
2
votes
1answer
63 views

Unable to override @salesforce/community/basePath mock within jest test

I'm trying to mock the @salesforce/community/basePath scoped module with different values for each jest test. I've mocked it globally : jest.mock( "@salesforce/i18n/lang", () => {...
0
votes
1answer
130 views

JEST Test LWC - render on conditional

How to write a jest test on conditional rendering? so I have a page in that page few input and combobox and when the combobox selected to a particular type which is accepted then I display the input ...
0
votes
1answer
86 views

How do you grab a title off of a button for Jest testing?

I am trying to grab a title off of a LWC button that is a basic component button with a title as title='Enabled button'. Right now I am checking if it is disabled by doing expect(selectBtn.disabled)....
1
vote
0answers
305 views

Do not import `@jest/globals` outside of the Jest test environment [closed]

I am using jest 25.5.1 , i am receiving error as "Do not import '@jest/globals' i see in this version it is not supported . Could you please help how to resolve this issue either how to downgrade ...
4
votes
1answer
118 views

JEST Skipping Tests when Coverage Option Used

I can run an individual JEST test successfully for this component: PS C:\Users\Dave2\Documents\Visual Studio Code\TMS> npm run test:unit dispatchConsoleCalendarCell.test.js > tms@1.0.0 test:...
3
votes
1answer
328 views

LWC Jest test fails when testing data returned after apex imperative call

I believe it is a simple fix, but I am new to everything and Jest being the latest one I am exposed to. I am trying to test if the lightning-combobox received the data to fill its options after the ...
1
vote
0answers
154 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
241 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
88 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
311 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 ...
3
votes
1answer
315 views

How to unit test a LWC component with @api fields

How can I use Jest to test a LWC component where data is provided via @api annotation? For example, I have a component unitTestComponent.js import { LightningElement, api } from 'lwc'; export ...
1
vote
0answers
87 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
76 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
1answer
90 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
102 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
153 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
184 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
557 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
33 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
111 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
246 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
262 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
158 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
58 views

How to Mock getRecordNotifyChange

How exactly do we mock getRecordNotifyChange in a JEST test? I cannot find an example anywhere.
2
votes
1answer
180 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
749 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
424 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
313 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
618 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 ...
1
vote
0answers
71 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....
5
votes
2answers
2k views

LWC + Jest: Mocking imperative Apex and returning a value

I'm going to do a Q&A-style entry here, since I couldn't find anything on the web describing this use case. I have seen several threads here describing how to do an empty mock on an Apex call in ...
1
vote
0answers
73 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
611 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
1k 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
1k 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
929 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,...
1
vote
1answer
264 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 ...
7
votes
1answer
962 views

Automated testing of Lightning Web Components?

Personally, I struggled to get value out of the Lightning Testing Service and felt it was very limited compared to e.g. Angular Testing. Working for an ISV, automated testing is key to keeping ...