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
41 views

LWC jest tests mock child component or use existing tests

I have multiple custom components. Code just for example. childLwc is standalone component and has its own tests. So my question is how can i use childLwc without mocking everything I need again. Can ...
  • 1
0 votes
1 answer
65 views

Salesforce LWC - State management in checkbox input control

I am new to salesforce LWC. Developing a page with a checkbox inside a component. So my task is to maintain the state of the checkbox even after the page refresh. For this, I used session management ...
  • 3
0 votes
1 answer
21 views

How to use objectContaining() or another method to assert that key/value pairs are in a request body in Jest

I am trying to assert that currencyIsoCode: 'USD' is in an HTTP request body. I am able to assert that method: 'POST' is in the request body, so I am assuming the problem has something to do with the ...
0 votes
0 answers
176 views

Jest Error - TypeError: this._environment.runScript is not a function

Test suite failed to run TypeError: this._environment.runScript is not a function at Runtime._execModule (node_modules/@salesforce/lwc-jest/node_modules/jest-runtime/build/index.js:856:41) Hey, I ...
  • 1
0 votes
0 answers
66 views

Issue when test connectedCallback method on LWC component that use more that one module mock

I have the following files to define a LWC. customComponent.js import {api, LightningElement} from "lwc"; import getResult01 from "@salesforce/apex/Controller01.getResult01"; ...
  • 101
0 votes
1 answer
42 views

Can't test LWC component with getRelatedListRecords LDS?

I create LWC component that contains wire service with importing getRelatedListRecords function. and its work normal. but the problem is when I create the test using jest-test I don't know why I ...
  • 109
0 votes
1 answer
85 views

LWC datatable jest testing: row action menu items

I would appreciate guidance on how to jest test row action menu items. Are there any reference docs, clear examples or advice, please? I am unable to find anything directly helpful. SF general type ...
2 votes
1 answer
354 views

LWC JEST: TypeError: expect(...).toBeAccessible is not a function

I am facing following error while running lwc test in newly created Salesforce DX project. I have installed JEST using sfdx force:lightning:lwc:test:setup command. This error I am facing only for ...
  • 1,280
0 votes
1 answer
25 views

lwc testing TypeError: element.wireRecord is not a function

I am trying to do a test when no records are returned. Error is here: element.wireRecord(wireRecord); test code is: it('Check no quote found error', () => { const element = createElement('c-bid-...
  • 61
0 votes
0 answers
62 views

jest lwc code coverage overlay not working

I can't get lwc jest code coverage overlay to work in vs code. I have installed the jest extension. jest.config.js is there with the following code: const { jestConfig } = require('@salesforce/...
  • 61
0 votes
0 answers
47 views

LWC JEST Debug Test issue- Unbound breakpoint

I am trying to debug lwc JEST for hello world for lwc recipe. https://github.com/trailheadapps/lwc-recipes For any test when I am adding breakpoint and selecting debug test option seeing following ...
  • 1,280
2 votes
1 answer
68 views

Mocked imperative Apex method does not return mocked value

My lwc has an input and a button. When I press the button an apex call with the input's value is made. Even though the method is called with the right params, the return value is some sort of empty ...
1 vote
1 answer
137 views

Cannot find module 'lightning/actions' import { CloseActionScreenEvent } from "lightning/actions";

Is there a valid solution for this issue in latest versions of @salesforce/sfdx-lwc-jest? I implemented the below solution and still get the error: "@salesforce/sfdx-lwc-jest": "1.1.0&...
3 votes
1 answer
40 views

Two Wires to same service confusing emits in Jest

I have this in an LWC: import {getObjectInfo} from 'lightning/uiObjectInfoApi'; @wire(getObjectInfo, { objectApiName: 'My_First_Object__c' }) receiveMyFirstInfo({error, data}) { if (data) { ...
0 votes
1 answer
122 views

Cannot mock an lwc getter with Jest

I created a lwc in which I can't mock a getter in the class for unit testing. The class is as follows: export default class CreateSubscription extends LightningElement { isSubAvailable; ... // ...
  • 1
0 votes
1 answer
2k views

Jest error:- TypeError: Cannot read properties of null (reading 'dispatchEvent')

I am failing to understand the error source in my first attempt at 'jesting'. import { createElement } from 'lwc'; import Lwcsearchcomponent from 'c/lwcsearchcomponent' describe('lwcsearchcomponent ...
0 votes
0 answers
622 views

Jest exceed timeout when using fake timers

I am writing jest test for search input and it give me an error that timeout is exceeded when i am using fake timers. I was trying to increase timeout but received the same error I have looked into ...
  • 31
0 votes
0 answers
191 views

LWC/Jest/PapaParse: How to ensure mocked function can call private function?

thanks in advance for any help! I'm currently trying to write a test for the following behavior: the User uploads a .csv file to a lightning-input element of my LWC, and an HTML element of the ...
  • 1
0 votes
0 answers
50 views

Jest test service lwc component with toast

I have service lwc, which has a few method and one of them display toast. Component doesnt has lightningElement and html so I have some problems with tests. Code looks like that. I dont understand how ...
  • 5
2 votes
1 answer
182 views

LWC jest mock custom permission: jest.mock( "@salesforce/customPermission/my-custom-permission",

I am mocking custom permission successfully like this: jest.mock( "@salesforce/customPermission/my-custom-permission", () => { return { default: true };...
  • 21
0 votes
0 answers
399 views

Writing a JEST Test for a Function that Contains a Promise and setTimeout

I'm trying to write a test for a Lightning Web Component that fires a custom event, which causes a function to execute in the component. The code for the test is below: it('make recurring ...
10 votes
2 answers
705 views

How can I test that my component, which implements the standard modal components, is working properly?

Since the update to API 56.0 (Winter '23) Salesforce introduced a new set of components to help developers create modals with the Lightning Experience format in an easier way. The components added ...
0 votes
0 answers
77 views

Jest Test Path Error

I've only been working with lwc a couple of weeks, and Jest even less so. I have a project in a directory which has a space in it's path (due to company directory structure), e.g., D:\AAA BBB\Projects\...
1 vote
0 answers
146 views

LWC Jest test can't set @api array/object

I have and array @api property and can't set it in test. It also doesnt work if I'm trying to pass object data and works if i pass just string. When I pass array or object it displays in lwc as [] or {...
  • 11
0 votes
1 answer
517 views

LWC jest test on conditional element

How can I test if:true element in my lwc? showLoadingSpinner is @api. I am new to jest, sorry if stupid question. Console log shows null. <template if:true={showLoadingSpinner}> <div id=&...
  • 25
0 votes
1 answer
182 views

Lightning button not rendered in jest test

I'm trying to write a jest test for lwc component, and facing an issue with rendering . For example, if we add the condition like this <template if:true={booleanFlagValue}> <lightning-...
2 votes
1 answer
687 views

Any way in LWC jest testing to make sure a child component received the right data from the parent?

I understand the philosophy that Jest is about "black box" testing, where you just observe the effects of the code. So you have limited access to things, and have to rely on observing ...
0 votes
0 answers
488 views

Jsforce connection leaves open handle when unit testing with Jest

I am trying to write a simple unit test for a Firebase function that connects to Salesforce using JSForce however when running the test, the unit test passes however jest throws a warning: Jest has ...
  • 1
0 votes
0 answers
1k views

How to Jest file upload

I am stuck with Jest testing of file resize/upload logic. This is a simple job to resize uploaded image and add it to the Notes & Attachments based on recordId. It is not a production code - it ...
2 votes
2 answers
517 views

Mocking Apex Wire Adapter - "emit is not a function"

I am trying to set up a very simple test of a LWC apex wire adapter. This includes mocking the apex response with the contents of a JSON file as shown in the LWC docs. ... import MyComponent from 'c/...
  • 423
0 votes
1 answer
69 views

JEST with Light DOM components

I'm trying to write tests for my LWC components. There also "Light DOM" components present but it seems like there is no support for it: This is the error I'm getting: Error: Assert ...
  • 31
0 votes
1 answer
127 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, ...
2 votes
1 answer
414 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 ...
  • 671
1 vote
1 answer
214 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 ...
  • 365
-2 votes
1 answer
168 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 { ...
  • 11
0 votes
1 answer
907 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' }) ...
0 votes
1 answer
821 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 ...
0 votes
1 answer
1k 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 ...
1 vote
1 answer
180 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 ...
  • 11
2 votes
1 answer
873 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 =...
0 votes
0 answers
403 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 ...
  • 2,823
0 votes
0 answers
84 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 ...
0 votes
1 answer
101 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 ...
1 vote
1 answer
266 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 ...
  • 314
0 votes
0 answers
562 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": &...
  • 314
3 votes
3 answers
793 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=...
1 vote
1 answer
347 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 ...
0 votes
1 answer
1k 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 ...
3 votes
1 answer
1k 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 ...
1 vote
1 answer
407 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 '...