People who code: we want your input. Take the Survey

Questions tagged [jest]

Questions related to using the `sfdx-lwc-jest` Jest test framework extension for the purpose of creating unit tests for Lightning Web Components.

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

test two events in same test case lwc jest

I have a change event on an input text box whose value will be added to an array on a click event. So two events here. How can we test array length on click action. Error: expect(received).toBe(...
2
votes
0answers
36 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. ...
0
votes
0answers
25 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/...
2
votes
2answers
43 views

Jest unit test fails for a property when it is not tagged by @api

That is a chunk of the JS code export default class CurrencyUI extends LightningElement { @api dropdownValue = 'USD'; That is the code for Jest it('Currency default value', () => { const ...
1
vote
0answers
69 views

Proper way to mock svg html template in Jest?

I want to create lwc component which selectively renders svg from html template files. I wonder how to mock that templates for the needs of JEST test. Import the same templates for component and test ...
3
votes
0answers
72 views

Declaratively mocking a custom LWC in a single unit test

The approaches suggested of using jestconfig module mapper or the mocks folder work well if you have a single mock per component you are testing, but not if you have to build how your parent component ...
1
vote
1answer
80 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
43 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',{ ...
1
vote
1answer
71 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 '@...
0
votes
1answer
1k views

LWC Error: Cannot set property 'textContent' of null

I have an lwc class with the following HTML: <template if:true={showModalButton}> <lightning-button class="right-col-button" variant="base" label={modalButtonLabel} ...
1
vote
0answers
46 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....
0
votes
1answer
385 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 ...
0
votes
0answers
35 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-...
0
votes
1answer
233 views

LWC + Jest: Tracking calls to a child component's @api-decorated functions

I struggled with this and couldn't find anything on Salesforce StackExchange or Google covering this kind of scenario in an LWC-specific context. So I'm going to post something Q&A-style. I have ...
2
votes
0answers
371 views

Test Class for LWC Component

I have a LWC Component which is used for record upload process. Below is my LWC Javascript code: import { LightningElement, api } from 'lwc'; import file1 from '@salesforce/apex/customLwcController....
1
vote
1answer
265 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
505 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
726 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
436 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
60 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() {...
0
votes
1answer
141 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 ...
1
vote
1answer
127 views

Cannot assert flowattributechangeevent in lwc test

I've created a lwc component that shows radio button. On Selecting the button, I call handleChange method as shown below. <template> <lightning-radio-group name="radioGroup" ...
2
votes
0answers
669 views

How to write jest test for lightning-datatable LWC

I'm populating the data table in the jest test successfully but when I try to select any row it comes up null which leads to this error TypeError: dataTableRow.click is not a function this is from my ...
1
vote
0answers
336 views

createElement error in jest test case (Lightning Web Component)

Error says the component is not a valid component, or does not extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration. Imported ...
2
votes
1answer
90 views

LWC test class failing

I have this apex wire method in an LWC Component @wire(getCountriesData, { proposalId: '$proposalId' }) countriesData(result) { this.wiredCountriesData = result; if (result.data) { ...
1
vote
1answer
853 views

where to see test code coverage for lwc jest Test

I have this below test class which is testing a getPicklistValues method on a LWC component named manageCountries. import { createElement } from 'lwc'; import ManageCountries from 'c/ManageCountries'; ...
0
votes
1answer
307 views

LWC Toast Event JEST Test Issue

I have a JEST test that tests for the presence of a toast event when an exception occurs from an imperative apex call: test('test exception path', () => { getStatusList.mockResolvedValue(...
0
votes
1answer
169 views

How to access static resource in JEST for lighting web component

We are importing JavaScript library in lwc using static resource, I want to test component using JEst. But static resource is not rendering while running the test class ? How can I render ?
1
vote
2answers
513 views

TypeError: Cannot read property 'getElement' of null

It seems like when I have the querySelector('') set to "lightning-card" I get an error. I'm not understanding why. TypeError: Cannot read property 'getElement' of null 19 | ...
0
votes
1answer
58 views

JEST issue - Wired Get Rec

I am writing a Jest to test Wire adapter import { createElement } from 'lwc'; import NtnxMWDRequest from 'c/ntnxMWDRequest'; import { registerLdsTestWireAdapter } from '@salesforce/sfdx-lwc-jest'; ...
2
votes
1answer
528 views

mocking getSelectedRows() method from standard lightning-datatable component's JS class in jest test not working

my LWC component under test have lightning-datatable with onrowselection event, that I want to test in jest. Here is code snippet for component: HTML: <lightning-datatable key-field=...
4
votes
1answer
509 views

LWC: Assertion error when testing @wire chain in Jest

I am trying to write Jest test for a component with two @wired calls (both bound to functions), but I get assertion error about property of second @wire call not being annotated with wire annotation. ...
1
vote
1answer
2k views

Get computed style in Jest Test

I have the following code. Html template <template> <tr class="table__row" aria-hidden={isHidden} data-test-class="table-row"> <td>Cell</td> ...
1
vote
2answers
868 views

npm command not found when working with jest in LWC

I am doing this trailhead module to get started with testing in LWC. The first step is to run below command sfdx force:lightning:lwc:test:setup But when I run this in terminal, I am getting a below ...
2
votes
1answer
407 views

Error: Cannot find module '@salesforce/client/formFactor' while testing my LWC

I am getting this error: Cannot find module '@salesforce/client/formFactor' when I run jest test, But it works in a scratch org. import { LightningElement, api } from "lwc"; import ...
2
votes
1answer
147 views

In an unit test for an LWC, how can I prove a method executes periodically according to metadata configuration?

I have the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-number currency-code="EUR" ...
1
vote
1answer
460 views

In an unit test for an LWC, how can I prove an async chain is setting a value in a lightning-formatted-number?

I am trying to prove that the price is being set on the component. I have the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-...
1
vote
1answer
624 views

In an unit test for an LWC, how can I mock out a fetch to a third party API?

I have a Lightning Web Component with the following HTML: <template> <h1>Current price of a bitcoin in Euro</h1> <lightning-formatted-number currency-code="EUR"...
2
votes
1answer
98 views

LWC Testing framework

We have a really nasty problem with the LWC Jest tests. Every single test takes too much time to execute on Windows. For example, the very same tests take 5 secs to execute on Mac and over 1 minute on ...
0
votes
0answers
72 views

Pass value to select tag throw test case in lwc using jest

it('should handleSelectedValue',() => { document.body.appendChild(selecteElement); const selectValue = selecteElement.shadowRoot.querySelector('select[name="select-value"]'); ...
6
votes
1answer
436 views

How to mock out custom labels in LWC for a DX org?

I was trying to write unit tests for some of my LWC components, however the ones that use custom labels throw the following exception [LWC error]: Invalid operation on Element [object:vm undefined (2)...
4
votes
3answers
2k views

sfdx force:lightning:lwc:test:run not working

I have written a bunch of tests for LWC. I'm trying to run it using sfdx force:lightning:lwc:test:run but I run into: ERROR running force:lightning:lwc:test:run: No lwc-jest executable found. ...
0
votes
1answer
215 views

Lightning Web Component Jest testing

Hi I am trying to test my child component from the Jest test for that I am trying to fire an event but I am getting an error. Code In Jest: let aBCL = element.shadowRoot.querySelector(a-b-list-k'); ...
0
votes
1answer
1k views

Cannot find module '@jest/globals' from 'abc.test.js'

Has anyone encountered this kind of an error? We had a bunch of jest js files that were working a few months but now are failing. Can any JEST experts help?
0
votes
1answer
1k views

Manipulating track variables in jest tests?

I haven't been able to find any examples or any super helpful info on this. I did find someone posting that track variables are not publicly available to element when you do this: const element = ...
3
votes
0answers
695 views

LWC - Jest test for Apex calls in wired function

We have a class that calls the getRecord uiAPI and then using the result makes an APEX call to get more details from another custom object. import { LightningElement, api, wire, track } from 'lwc'; ...
1
vote
1answer
159 views

JEST Test FrameWork not able to put assertion on the basis of HTML tag

I need to put an assertion on the basis of HTML title in my JEST test Please find the code as below: import {createElement} from 'lwc'; import MeetingRooms from 'c/meetingRooms'; describe( 'c-...
1
vote
1answer
50 views

Jest Testing FrameWork createElement is not a method

need one help from the community below is my code for the JEST testing for one of my component. import { createElement } from 'c/meetingRooms'; import MeetingRooms from 'c/meetingRooms'; describe('c-...
0
votes
1answer
31 views

Jest Test Implementation [closed]

Hi I need to mock the scenario as below but getting stuck as data is not getting pulled from the JSON testDataJSon { "testpos":[ { "test1": false, "test2":true ...
0
votes
1answer
2k views

Simulate keydown event in JEST [closed]

I have an event listener in my JS controllerwhich i want to simulate in JEST case. event listener goes like this const element = this.template.querySelector('Something'); element.addEventListener('...