Hot answers tagged

3

You can just pass e. g. a file name after your script name E. g: npm run test:unit mycomponent.test.js Would all tests matching a file named mycomponent.test.js


3

The comment from @muenzpraeger was correct. The event handler won't fire on its own, so it needs to be fired directly from the test. So the test.js would look something like this: var element = createElement('c-test-component', {is: TestComponent}); document.body.appendChild(element); const handler = jest.fn(); element.addEventListener('formsaved', ...


2

Turns out that it is possible to get the component's attributes in a simple way, just accessing them directly, like: expect(comp.mapMarkers).toHaveLength(2) The catch here is that you have to "return a promise in the unit test, to wait for any asynchronous DOM updates. Jest will automatically wait for the Promise chain to complete before ending the test ...


2

Different Context but the same answer ;) As you can see here the stub was not updated since two months. You can: Open an Issue in the repo (that makes sense anyways i guess) and wait for an official fix You can locally edit the stubs in the package and add the attribute (or fork the repo and do it there) You can provide a own stub as explained here


1

Jest is necessary for unit testing your lightning web components. There is no hard requirement today to have unit tests for lightning components unlike apex unit tests. Also jest tests for lwc has no relation to security of your app .Hence it's not mandatory to have jest tests for your web components when you submit to security review .


1

Most info copied from discussion on the sample git commit here. The technique you used to mock out the navigator.geolocation API is fine. The relevant code block from the original question is the following: const mockGeolocation = { getCurrentPosition: jest.fn().mockImplementation((success) => Promise.resolve( success({ ...


Only top voted, non community-wiki answers of a minimum length are eligible