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
2
votes
1answer
39 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
20 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
29 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
25 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" ...
1
vote
0answers
44 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
41 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 ...
1
vote
1answer
33 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
52 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
36 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
28 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
89 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
26 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'; ...
1
vote
1answer
81 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=...
1
vote
0answers
78 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. ...
0
votes
1answer
232 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
322 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
78 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
31 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
89 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
86 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
59 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
36 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"]'); ...
4
votes
1answer
129 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
959 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
49 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
237 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
88 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 = ...
2
votes
0answers
192 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
45 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
30 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
201 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('...
0
votes
1answer
20 views

Test Suites vs Tests [duplicate]

I ran all jest unit tests. The results are in the image below. What is the difference between a test suite & a test? Is a Test Suite equivalent to a test class and a Test equivalent a test method ...
0
votes
0answers
186 views

LWC Jest Error - Invalid template iteration for value “undefined” in [object:vm undefined (1)]. It must be an Array or an iterable Object

Hi I get the following error when i try to run jest test for a method with wire service The json am passing is as follows {"data":[ { "Id": "a5D2V0000000NvZUAU", ...
3
votes
1answer
45 views

How do you run all the Jest LWC tests at once in VSCode?

The "Run Test" link is provided for each test as illustrated below. But what is the easiest way to run all of the tests in the file?
6
votes
2answers
97 views

What repositories of LWC Jest tests are publicly available?

I've been looking at example Jest tests here trailheadapps / lwc-recipes but don't see examples of e.g.: injecting keys multiple layers of promises (see "best guess" below) factoring out of common ...
0
votes
0answers
259 views

LWC Jest Wired apex method after Imperative apex call

Inside the component, I have a wired apex method that depends on the results of an earlier imperative method. e.g: getUserId().then(data=>{ this.self = data; }); @wire(getUserDetails, {id: '...
2
votes
1answer
532 views

How to check the CustomEvent detail in a Jest test for an LWC?

I'm on my first day of writing Jest tests for one of our LWCs, and that component fires an event with some dates included as the event detail: @api get selectedDates() { return this....
0
votes
1answer
116 views

how to test getter in salesforce lightning web components using jest? [closed]

HI All i want write test case for getters in lwc component using jest can anyone help in this? JS Code: get isDefaultVariant() { if (this.variant.toLowerCase() === "default") { return true; } ...
1
vote
1answer
69 views

Combobox value update is not reflecting in jest test

I have created a basic lwc component that displays a Combobox(base component) and shows the selected value below it. When I'm trying to test the combobox selection in jest, even after updating the ...
1
vote
1answer
173 views

I want to cover the onBlur event in javascript by writing JEST test case in LWC

In my html component i've used an onBlur attribute in div. While writing the test case for the same i am unable to cover the javascript method which I've called in html. My div looks like this <...
2
votes
0answers
114 views

Test lightning-emp-api

Can we simulate an event subscription in LWC unit test? I have a lightning web component using lighting/empApi like, export default class ExampleComponent extends LightningElement { ...
4
votes
1answer
187 views

Parsing Jest response and fail Bitbucket Pipeline

This is an extension to Lean and reusable DX Bitbucket Pipeline for PR checks. Similar to Apex tests I also want to run all JEST tests when a scratch org is created using my shell scripts AND from ...
5
votes
1answer
311 views

Getting error when running Jest tests with sfdx project at version 48

When running the Jest test I'm getting this error: Invalid sourceApiVersion found in sfdx-project.json. Expected 47.0, found 48.0 error My sfdx-project.json looks like this { "...
6
votes
1answer
114 views

What's the difference between sfdx-lwc-jest & lwc/jest-preset?

I'm trying to set up Jest for LWC. I have looked at the documentation and I have looked at the LWC website. Both of them refer to different packages for Jest installation. Which one should I use? and ...
2
votes
1answer
118 views

Does sfdx-lwc-jest support the TAP or JUnit test result format that CI servers can consume?

As far as I can see, the salesforce/sfdx-lwc-jest LWC JavaScript test framework does not support the simple TAP (Test Anything Protocol) output format that CI (Continuous Integration) servers such as ...
0
votes
1answer
398 views

LWC Jest Test - Why i keep receive 0 in my Test

I'm trying to make unit test with Jest for my lightning web component. I'm trying to check if the data binded in my html are rendering correctly. It seems like when i'm running the test, it doesn't ...
2
votes
1answer
106 views

TypeError: “createElement” function expects a “is” option with a valid component constructor

guys! I'm trying to test my LWC component, but I keep getting TypeError. This is a simple as hell LWC component, that displays text in the center of a page. You enter text in an input, and, on a ...
10
votes
2answers
479 views

Testing LWC with multiple @wire getRecord calls with Jest

I thought this would be straight-forward, but it turns out to be a complete nightmare. Found no help on google, in the lwc-recipes or documentation. Here's my issue: I have a LWC that makes multiple ...
3
votes
1answer
108 views

Jest test lightning-record-edit-form on submit event with preventDefault

I would like to add a simple jest test to my lightning web component in order to test the functionality of the following on submit event handler. handleSubmit(event) { event.preventDefault(); ...