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
0
votes
0answers
18 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
54 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
27 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
119 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
19 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
173 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
51 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
105 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
169 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
197 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 ...
4
votes
1answer
169 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
76 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
37 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
85 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
75 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
234 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
123 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
115 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
89 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
193 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
686 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
375 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
977 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
162 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 ...