Questions tagged [jest]

Jest is the JavaScript unit testing framework recommended by Salesforce for use with Lightning Web Components.

Filter by
Sorted by
Tagged with
3
votes
1answer
32 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
54 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
20 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
35 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
34 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
19 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
0answers
25 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
37 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
45 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
77 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 { "...
5
votes
1answer
74 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
48 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
88 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 ...
1
vote
1answer
39 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 ...
7
votes
1answer
128 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 ...
1
vote
1answer
45 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(); ...
1
vote
1answer
294 views

Jest Test - element.shadowRoot.querySelector() not retrieving element when given an id

I am attempting to retrieve and make assertions about certain elements using querySelector() with the respective id of that element. But, querySelector() isn't returning any elements with a given id. ...
2
votes
1answer
61 views

LWC + Jest: Make assertions about an element's rendered style

In a LWC project, I'm setting certain child component style properties from the parent component. I want to test that an element in a child component shows up with those properties when it's rendered,...
1
vote
1answer
296 views

LWC: unit testing component using validity object

I have an lwc component which validates some input fields before performing a post request to the server. I'm writing a unit test where I'm testing that the post request is called when all input ...
0
votes
0answers
27 views

LWC tests without Salesforce DX project structure

Is there any way to test LightingWebComponent in the salesforce project which doesn't has a DX project structure? In the documentation we can see that sfdx-lwc-jest works in Salesforce DX projects ...
0
votes
1answer
440 views

How to mock custom LWC components in JEST

I am still new to JavaScript and especially Jest, so apologies in advance for the maybe stupid and uninformed question. To isolate my tests, I want to mock one of my custom table components. In short,...
1
vote
0answers
138 views

Lightning web component unit testing. Issue with testing row action event

Firstly, I wanted to indicate that I have poured over the LWC Recipes repo to find this, and I can't. I am trying to get test coverage on a Lightning Web Component. The component has two Sub ...
3
votes
2answers
234 views

LWC Jest querySelector cannot read property 'value' of null

New to LWC and Jest -- and trying to write a succinct test on a component with multiple lightning-input elements. I have used the following pattern, which works fine -- I get a passing result: let ...
1
vote
1answer
261 views

ShowToastEvent is not working for jest test class

MyLighingwebcomponent <template> <lightning-card title="Custom Search Functionality in LWC" icon-name="standard:account"> <div class="slds-m-around_medium"> &...
0
votes
1answer
345 views

Error: Cannot find module '@salesforce/sfdx-lwc-jest/config' while testing my LWC from vs code

I have started my practice on LWC testing While i'm run this command:"npm run test:unit" i am getting this error:Cannot find module '@salesforce/sfdx-lwc-jest/config'. Error body is: Error: Cannot ...
5
votes
1answer
319 views

Mocking CurrentPageReference wire in Jest unit tests - LWC

I have a LWC component which uses CurrentPageReference from lightning/navigation bundle in a @wire function. I am using lwc-jest to create unit tests for my components. Using the wire with ...
0
votes
0answers
105 views

Warning when dispatching ShowToastEvent

I'm trying to follow the pattern in https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_toast for displaying a toast message. However, whenever I do I get the following ...
2
votes
0answers
61 views

Warning when setting input value in test

I'm writing unit tests for LWC using lwc-jest but when I try to follow the pattern documented in the Basic Lightning Component section of this documentation https://developer.salesforce.com/docs/...
0
votes
0answers
119 views

Test cases for LWCs with conditional rendering

I have a LWC component which looks like below <template> <!-- modal start --> <template if:true={booleanField}> <lightning-record-edit-form object-api-name="...
0
votes
0answers
95 views

lightning-record-form onError jest test

I'm looking at writing a jest test for the lightning-record-form to test the error handling, The full function should be onError display a Toast event stating the error message to the user const ...
5
votes
0answers
332 views

My LWC test is not displaying code coverage

I have configured jest for Lightning web component test. My tests are running and passing but code coverage not displaying into output. Following is package.json file: - { "name": "my-...
4
votes
0answers
158 views

Jest Unit test an event that dispatches inside XMLHTTPRequest (XHR)

How do I test an event that does an XHR request and dispatches an event? I managed to install the dependencies to mock the xhr using https://github.com/jameslnewell/xhr-mock/tree/master/packages/xhr-...
1
vote
1answer
131 views

LWC Jest tests failing when adding variant to lightning-radio-group

This is similar to a previous question, however the context is different. We have developed a custom LWC that uses the lightning-radio-group component and sets the variant so we can hide the label (...
4
votes
1answer
103 views

Is Jest mandatory in LWC For appExchange app

As SF stated Jest is independent of Salesforce and doesn't run in web browser. Is it mandatory to write coverage/unit testing for Lightning Web Components and add in bundle while creating manage ...
2
votes
1answer
263 views

Run Single Test for Lightning Web Component

I feel like this is a stupid question, but I can't find the answer anywhere. Is there a way to run a single test file for a single Lightning Web Component. I essentially want to be able to pass ...
2
votes
1answer
972 views

How can I test the click of a button that calls an Apex method, and makes the component show a toast?

The component itself, when loaded, queries some data from the database. Then, depending on what it finds, loads the specific template. One of those has a button, which will call the server again, and ...
5
votes
1answer
484 views

How to mock navigator.geolocation in a LWC?

Having a component that uses the embedded geolocation feature to get coordinates, how can I mock the call in a Jest test? The component's code work in the org: ... get locationService () { ...
3
votes
1answer
1k views

How to test LWC onsuccess event handler in Jest

I'm looking for help writing jest test for my onsuccess event handler for my lightning-record-edit form. I'm new to jest so forgive me if this is covered somewhere else, I just haven't been able to ...
5
votes
1answer
207 views

How can I make sure, in an unit test, that I have the correct data in a lightning-map component?

If I have a property called markers in my component, which is exposed using the @api notation. How can I make sure that it contains the correct values after the component goes through the jest unit ...