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
0 answers
19 views

Unable to create Jest tests for generation 2 package

I have created an LWC app, and am now trying to add code test coverage. But unfortunately, Jest (@salesforce/sfdx-lwc-jest@1.1.1) is failing in two different ways: I use the getRecords wire adapter, ...
user avatar
2 votes
1 answer
44 views

Testing LWC with Jest, datatable data array length not updating after promises are resolved

I've been writing lwcs since they came out, but never wrote unit tests for them. Just getting my feet wet here :) I have an lwc with three datatables. The first one has row actions that process the ...
user avatar
  • 661
1 vote
1 answer
32 views

Jest error: Cannot find module 'lightning/alert' from '.../newAccount.test.js'

When I run the test for my LWC I have this error: I read about other issues like that where the solution is to mock the missing function but I cant find something related to action in the repo my ...
user avatar
  • 353
-3 votes
1 answer
60 views

Make Jest for LWC [closed]

I have controller.js . It returns the ID of the case and displays duplicates of this case on the case page. The code works without problems, but it doesn't work with tests in any way import { ...
user avatar
  • 1
0 votes
1 answer
101 views

Getting a null error in Jest test

i am new to LWC and jest test.So while doing the testing i have got an error. TypeError: Cannot read properties of null (reading 'style') js file @wire(getItemProperty, { iId: '$contactId' }) ...
user avatar
0 votes
1 answer
122 views

How to select an element inside a template if true in LWC Jest test?

I have an LWC app that has a lightning-input and a lighning-button. It fetches data from the server for a record whose ID is specified. I have successfully mocked the server calls. I am trying to ...
user avatar
0 votes
1 answer
111 views

How do you click on checkbox group in jest?

I am trying to JEST test a checkbox group that has 1 option and when I do .click() it says can't click null property. Is there a different way I should be hitting it with JEST? For clarification, the ...
user avatar
1 vote
0 answers
33 views

Wire Service Jest Test - Config Object Empty so filterFn not working properly

So, I followed: https://github.com/salesforce/wire-service-jest-util Testing LWC with multiple @wire getRecord calls with Jest to help get my test configuration setup for multiple @wire getRecord ...
user avatar
  • 11
2 votes
1 answer
148 views

How to use Cobertura and JUnit reporters with LWC Jest?

When creating a new SFDX project, the default Jest configuration for LWC unit tests looks like this: jest.config.js const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config'); module.exports =...
user avatar
0 votes
0 answers
85 views

jest dom is not updating after element.innerText is set imperatively

I am testing a component that renders a table. Each row of the table body has a column that contains a button, when the button is pressed a javascript handler modifies the cell by setting the ...
user avatar
  • 2,605
0 votes
0 answers
29 views

LWC Could show checkbox group inside lightning-tabset correctly

In order to provide users with a UI in which he could select some products with groups of products based on global category I am trying to show lightning-checkbox-group inside lightning-tabset, this ...
user avatar
0 votes
1 answer
22 views

Error in executing JEST Unit Test cases in react-native project with Salesforce Mobile SDK created by forcereact

We are creating React-Native mobile App Using Salesforce Mobile SDK. In this project we setup JEST for unit test cases writing. But whenever it goes into Salesforce Mobile SDK API it failed and sends ...
user avatar
1 vote
1 answer
101 views

getPicklistValues jest test

I have two wire calls to getPicklistValues method in my LWC component. In my jest test I am calling getPicklistValues twice to emit the test data based on different configs. However the mocking is not ...
user avatar
  • 304
0 votes
0 answers
184 views

ReferenceError: MutationObserver is not defined - LWC Jest test

I am facing this error while executing lwc jest tests. My source api version is 52 and package.json devdependencies looks like this: "devDependencies": { "@salesforce/core": &...
user avatar
  • 304
3 votes
3 answers
481 views

Is it alright to change properties to @api so they can be tested in unit test in lwc jest

So I want to test if my breadcrumb child component shows expected breadcrumb when I go to a certain url, for instance when I go to say http:// <domain>?c__view=contractDetail&c__id=...
user avatar
1 vote
1 answer
163 views

CurrentPageReference setter not getting called when I mock in jest unit test for lwc

referencing this answer:Mocking CurrentPageReference wire in Jest unit tests - LWC This is how I mock CurrentPageReference in the test file , the navigate functionality seem to work but I can't call ...
user avatar
0 votes
1 answer
366 views

How to test methods that change object fields (and some others methods) not decorated with @api using JEST in LWC

My LWC application includes a modal window and is written for use in Salesforce and uses Apex. I had a hard time writing tests for some functions, but I couldn't test the application until the end. I ...
user avatar
3 votes
1 answer
565 views

Format JSON data With Dot Notation for Jest Mock

I have an input field that reads a value from an api property. Everything works fine except when I try to write a test Test to mock the data. I am assuming that I must be making some kind of mistake ...
user avatar
1 vote
1 answer
164 views

JestTest Failes at Rendered CallBack With Wire and Conditional Rendering

I have been hacking at this for a few days. I have an LWC with a wired Apex method. When it gets into the renderedCallBack() and tries to assign focus to an element the test fails with a message of '...
user avatar
1 vote
1 answer
236 views

How would I JEST test a @wire(CurrentPagereference)?

I am unable to hit these lines of code even after I added some jest-mocks to my test folder. I am sure that I would have to do something like below, but how would I then hit it to verify what is ...
user avatar
3 votes
1 answer
1k views

How do you JEST test a simple click with no event?

I am trying to JEST test these two buttons but I am currently not hitting these two functions in my LWC Coverage. I tried doing btn.click() on them and then resolving them in a promise to check the to ...
user avatar
0 votes
1 answer
138 views

When testing a Salesfore LWC component which is better if (boolean Value === true) vs if (boolean Value === 1)?

My test data has a value in it like this: "preSelected": 1, amongst other values which are part of a mock of apex returned data. In my js code I test against this value like this: for ...
user avatar
4 votes
1 answer
509 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 --...
user avatar
0 votes
1 answer
88 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) => ...
user avatar
0 votes
1 answer
650 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 ...
user avatar
0 votes
1 answer
87 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({ ...
user avatar
  • 687
1 vote
1 answer
1k 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}&...
user avatar
0 votes
0 answers
136 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: ...
user avatar
1 vote
1 answer
103 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-...
user avatar
  • 111
4 votes
1 answer
674 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 ...
user avatar
0 votes
1 answer
287 views

LWC Jest testing toasts

I'm having an issue with testing toasts. I have read a lot about this thanks to google and followed the instructions but I can't seem to test my toast. When I step through the test, I have a ...
user avatar
  • 25
0 votes
1 answer
293 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 ...
user avatar
  • 25
2 votes
1 answer
380 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 ...
user avatar
  • 33
2 votes
1 answer
313 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 ...
user avatar
  • 12.7k
0 votes
0 answers
168 views

JEST Coverage for LWC

I have made an LWC component and all functionality seems to be working, however, I am struggling to get test coverage for some functions. I have built some tests for them but according to the code ...
user avatar
0 votes
0 answers
51 views

using query selector with variables

it was my understanding that you could use variables in a query selector (though i could be wrong, it seems), yet this code fails: let fields = [".cmwc__ref_purchdate","....
user avatar
2 votes
1 answer
192 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", () => {...
user avatar
0 votes
1 answer
576 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 ...
user avatar
  • 6,672
0 votes
1 answer
313 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)....
user avatar
1 vote
0 answers
830 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 ...
user avatar
4 votes
1 answer
441 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:...
user avatar
  • 305
3 votes
1 answer
868 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 ...
user avatar
  • 503
2 votes
1 answer
233 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/...
user avatar
1 vote
1 answer
473 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 ...
user avatar
  • 130k
1 vote
0 answers
120 views

Why isn't jest being installed with @salesforce/sfdx-lwc-jest?

I'm working with a new project and tried to commit my first Lightning Web Component. I got this error: ESLint: 7.30.0 Error: Error while loading rule 'jest/no-deprecated-functions': Unable to detect ...
user avatar
  • 663
1 vote
1 answer
140 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-...
user avatar
  • 21
0 votes
1 answer
780 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 ...
user avatar
  • 113
3 votes
1 answer
921 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 ...
user avatar
1 vote
0 answers
128 views

LWC JEST test for API callouts [duplicate]

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 ...
user avatar
  • 97
0 votes
1 answer
176 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') { ...
user avatar