I have a function that saves an entity and in the promise i want to check the delete is called. In my jest test it whizzes past and can’t think how to test it Here is the partial snippets, it all …
Tag: testing
Test clearing of search input field on submit (after fetching)
I want to test that a search box does calls a handler (passed as prop) with the fetched results and resets the input field afterwards. import React, { useState } from ‘react’ import Axios from ‘axios’ …
Lightweight web browser for testing
I have e very specific test setup in mind. I would like to start a web-browser that understands Javascript and can use HTTP proxy, point it to a URL (ideally by specifying it in the command line along with the proxy config), wait for the page to load while listening (in the proxy) requests are […]
Jest equivalent to RSpec lazy evaluated variables (let)?
In rspec you can do something like this: This allows you to define a method call or instantiation of a large object as a sum of its smaller parts. You can then override those individual small parts inside different contexts. The idea being that you create a happy path before each test, and then specify […]
node.js mocha before function runs after test execution
I have moved this around so much and tried with done(), asyncand chaining then(), moving the describe() around and my latest attempt was to return a promise in the before as Async function in mocha before() is alway finished before it() spec? suggested. The console.log(‘finished!’) that indicates the tables have been created is printed way […]
Is there a reliable way to have Cypress exit as soon as a test fails?
We have a large test suite running on a CI server, and there appears to be no way of telling Cypress to exit if a test fails. It always runs the entire suite. There is some discussion here, but no …
How to mock window.navigator.language using jest
I am trying to mock the window.navigator.language attribute in the browser in my jest unit tests so I can test that the content on my page is using the correct language I have found people online …
How to spy on a recursive function in JavaScript
Note: I’ve seen variations of this question asked in different ways and in reference to different testing tools. I thought it would useful to have the issue and solution clearly described. My tests …
Jest TypeError: fetch is not a function
I have the following Jest test code to test a fetch to an endpoint: But I am getting: I know that the movieApiService.getPopularMovies() is a JavaScript fetch request, but Node.js does not have the fetch API, so how I can I make this test to work using Jest? Answer I can’t test this with the code you supply, but installing
Invalidate node cache when using Jest
I have a file with object that gets populated with process.env properties: env.js Now I try to test this file with different process.env properties: env.test.js Unfortunately, even though I try to load the file in every test separately the file gets loaded only once, making the third test fail with: P.S. It doesn’t fail when I run the test alone.