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

JEST Testing for wire methods

import { createElement } from 'lwc'; import ConversationWebComponent from 'c/conversationWebComponent'; import {setImmediate} from 'timers'; import getConversationData from '@salesforce/apex/...
Munib Ahmed's user avatar
1 vote
0 answers
33 views

Jest framework createElement import error

I've done a bit of looking around and the general answer for this import error is make sure the __test__ directory is added to the .forceignore. I have been following the LWC Tests module but I am ...
Matthew H's user avatar
0 votes
0 answers
42 views

LWC test async call from button click

I have a custom lightning web component that I want to pass tests but I'm not being able to accomplish with an async call fired from a button click. html <lightning-button label="Validate"...
molinet's user avatar
  • 915
0 votes
1 answer
93 views

LWC Jest: test a component that uses lightning/toast

The lightning/toast utility is GA as of Winter '24, but I haven't seen anything on StackExchange or in the docs about how to write tests for components that use it. One you import it into a component ...
Matthew Souther's user avatar
0 votes
0 answers
240 views

Access this.refs / lwc:refs="" when testing in jest?

I am attempting to use this.refs from with a jest test like this: <template> <input lwc:ref="inputEl" /> </template> // input.test.js import { createElement } from 'lwc' ...
lu_ke____'s user avatar
  • 433
2 votes
1 answer
173 views

How to write jest unit test to verify Nebula logger methods are called

I am using Nebula logger in my lwc to log errors but lost on how to write jest unit test that verifies nebula logger methods are actually called. Here is sample code: myLwc.js import { createLogger } ...
javanoob's user avatar
  • 8,847
0 votes
1 answer
110 views

Calling child component dynamically until a condition is met

I have recently started coding in LWC and I have a use case that -> I need to call this c-component2 repeatedly from `mycomponent1.html until a condition is met. Is there something I can do to ...
monk's user avatar
  • 3
0 votes
1 answer
6k views

How to use Fetch in Jest Javascript Test

Setting aside that making HTTP requests during tests isn't the best practice. I am trying to use fetch, but I am getting this error: ReferenceError: fetch is not defined Here is the code: describe('...
Robs's user avatar
  • 9,328
0 votes
0 answers
114 views

How to cover 'Import communityPath from '@salesforce/community/basePath'; in Jest (for LWC)

cmp.js File Import communityPath from '@salesforce/community/basePath'; test.js File jest.mock( '@salesforce/community/basePath', ()=>({ default : '/mocked/community/basePath'}), ); But ...
Mondal Sucharita's user avatar
1 vote
1 answer
113 views

Testing LWC component using jest-cucumber but createElement not working as expected

I am writing a tests for my LWC component using jest-cucumber. This is my test: defineFeature(feature, test => { beforeEach(() => { element = createElement('c-myLwcElement', { ...
ViqMontana's user avatar
3 votes
0 answers
930 views

Error in LWC test: LWC1127: Invalid directive "$lwc:if" on element <template>

I have the following in my html template using lwc:if: <template lwc:if={showSpinner}> <lightning-spinner alternative-text="Loading" size="large"></lightning-...
ViqMontana's user avatar
0 votes
1 answer
33 views

Jest Test Case Reporting

Is there a way to publish Jest test case results? i.e., instead of only having test cases run locally on a single developers machine, is there a way to upload them to your org or github to be run in ...
JMRiss's user avatar
  • 45
3 votes
1 answer
2k views

How do I mock a child LWC in a parent's Jest Unit Test?

I have two components that are in my app: parentComponent childComponent. 'parentComponent' includes 'childComponent' as a component. E.g: parentComponent.html <template> <c-child-...
Rob Baillie's user avatar
0 votes
1 answer
426 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 ...
monk's user avatar
  • 3
0 votes
1 answer
339 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 ...
Kristina's user avatar
0 votes
0 answers
718 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 ...
Anyja's user avatar
  • 1
0 votes
1 answer
253 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 ...
naticap's user avatar
  • 121
0 votes
1 answer
307 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 ...
Stoicorum's user avatar
3 votes
1 answer
1k 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 ...
amitghadage's user avatar
  • 1,340
0 votes
1 answer
114 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-...
Col's user avatar
  • 61
2 votes
1 answer
289 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 ...
Christian Llanos's user avatar
1 vote
1 answer
907 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&...
Learning SQL's user avatar
3 votes
1 answer
158 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) { ...
Colin Steel's user avatar
0 votes
1 answer
525 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; ... // ...
Corey's user avatar
  • 1
0 votes
1 answer
9k 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 ...
Stoicorum's user avatar
0 votes
0 answers
2k 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 ...
ravipo's user avatar
  • 43
0 votes
0 answers
471 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 ...
CurtD's user avatar
  • 1
2 votes
1 answer
473 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 };...
Mira's user avatar
  • 21
0 votes
0 answers
912 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 ...
Daniel Fuller's user avatar
13 votes
4 answers
3k 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 ...
Renato Oliveira's user avatar
1 vote
0 answers
261 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 {...
kefow's user avatar
  • 11
0 votes
1 answer
1k 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=&...
raholed's user avatar
  • 25
0 votes
1 answer
550 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-...
Viktoriia Yefimova's user avatar
2 votes
1 answer
1k 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 ...
Jeffrey Gunn's user avatar
0 votes
0 answers
2k 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 ...
Alex__c's user avatar
2 votes
2 answers
2k 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/...
lemming's user avatar
  • 473
0 votes
1 answer
126 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 ...
MtheD's user avatar
  • 31
0 votes
1 answer
276 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/[email protected]) is failing in two different ways: I use the getRecords wire adapter, ...
user2943799's user avatar
2 votes
1 answer
880 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 ...
hgolov's user avatar
  • 733
1 vote
1 answer
405 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 ...
Badbaxx's user avatar
  • 375
-2 votes
1 answer
381 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 { ...
ALex's user avatar
  • 11
1 vote
1 answer
1k 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' }) ...
Teancy John's user avatar
0 votes
1 answer
2k 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 ...
darthcoderUS's user avatar
0 votes
1 answer
2k 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 ...
Tristan Berger's user avatar
1 vote
1 answer
361 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 ...
adam's user avatar
  • 11
2 votes
1 answer
2k 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 =...
Sebastiano Schwarz's user avatar
0 votes
0 answers
699 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 ...
TemporaryFix's user avatar
  • 2,937
0 votes
1 answer
166 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 ...
Satish K. Azad's user avatar
1 vote
2 answers
587 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 ...
Amit's user avatar
  • 344
0 votes
0 answers
870 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": &...
Amit's user avatar
  • 344