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.
81
questions
0
votes
1answer
100 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} ...
0
votes
0answers
28 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
39 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
20 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
18 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
141 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
58 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)
...
2
votes
1answer
127 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
202 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: ...
2
votes
1answer
182 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
35 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
71 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
55 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
249 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
85 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
57 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
333 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
123 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
94 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
235 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
39 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
207 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
285 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
796 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
532 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
165 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
94 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
226 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
277 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
76 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
46 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"]');
...
5
votes
1answer
252 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
1k 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
93 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
516 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
435 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
439 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
84 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
33 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
594 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
23 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
305 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
56 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
113 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
403 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: '...
4
votes
1answer
1k 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
216 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
212 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
499 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
<...