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
1 answer
54 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') html <template> <div class="slds-grid slds-...
user avatar
0 votes
1 answer
40 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
22 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
20 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
54 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
48 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,586
0 votes
0 answers
26 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
21 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
71 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
107 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
377 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
126 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
237 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
399 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
90 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
166 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
653 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
105 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
413 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
74 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
500 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
73 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
786 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
92 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
86 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
545 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
214 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
214 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
264 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
258 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
135 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
36 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
148 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
436 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,614
0 votes
1 answer
262 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
691 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
308 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
  • 295
3 votes
1 answer
717 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
  • 501
2 votes
1 answer
207 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
402 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
91 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
126 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
650 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
771 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
161 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
3 votes
0 answers
151 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. ...
user avatar
  • 130k
3 votes
1 answer
173 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! ...
user avatar
  • 295
1 vote
0 answers
279 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/...
user avatar
  • 334
1 vote
0 answers
985 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 ...
user avatar
  • 295