Most voted "jest" questions
Use this tag for questions related to the Javascript Test Jest framework.
Learn more…44 questions
Sort by count of
-
7
votes1
answer128
viewsHow to integrate Jest and Flow
I know some people use the Jest together with the Flow, even more for being from Facebook, I’m with a project React, and I’m trying to do this integration, but Jest does not recognize the typing…
-
5
votes1
answer241
viewsHow to test Exports of a package?
I have a file index.ts which is responsible for exporting all components as follows: export * from './components/com1' export * from './components/com2' export * from './components/com3' export *…
-
5
votes2
answers470
viewsHow to apply mock in "new date()" using Jest?
Please someone knows how to apply mock in the new Date() using the Jest? I tried to do so, but it did not work. The date remains current: jest.spyOn(Date, 'now').mockImplementation(() => { return…
-
4
votes3
answers109
viewsHow to compare arrays ignoring the order of the elements in Jest?
In a situation where I have two arrays, it is possible to use the expect of Jest for a comparison where I hope arrays are equal, regardless of the order of the elements? I searched, but found no…
-
3
votes1
answer173
viewsHow to Refactor Legacy JS to Implement Unit Tests?
I have a Wordpress site with many JS files that have not been structured to be tested - they have not been written as modules that can be imported nor is there a app.js that loads them all as a…
javascript unit-testing refactoring jasmine jestasked 6 years, 5 months ago Ricardo Moraleida 4,005 -
2
votes1
answer339
viewsUnit test of a javascript fetch function with jest or mocha
I’m starting studies with TDD and came across a function like this: const fetchexample = callback => { fetch('/token', { method: 'POST', body: 'user=teste' }).then(res => res.json()).then(json…
-
2
votes0
answers45
viewsHow to simulate a click function on an HTML file using Jest?
I’m starting to create tests for a simple HTML page, it has a script with some functions and my idea is to test these functions. But I can’t simulate a click on the DOM inside my test, how can I do…
-
2
votes1
answer211
viewsTypeerror: replaceAll is not a Function
I am developing a system in Electron that works well, but when running the tests in Jest I get the following error: console.error Error: Uncaught [TypeError: value.replaceAll is not a function] at…
-
1
votes1
answer38
viewsJest ignoring package.json specifications
I am implementing tests in my web application in React with jest. As it was started with the "create-React-app" it was easy to set up the environment. But for some reason jest seems to ignore…
-
1
votes1
answer37
viewsHow to capture an event in a stub? [Vue-test-utils]
I’m trying to test an event similar to this: // template: <form @submit.prevent="save"></form> const save = jest.fn() const wrapper = mount(MyComponent, {methods: { save }})…
-
1
votes1
answer60
viewsTest failure - setup.ts
Galley, I’m trying to run an App component test, however jest is interpreting setup.ts as a test. I’ve pointed it out as a setup in package.json, but it doesn’t work. Setup ts. import Enzyme from…
-
1
votes1
answer36
viewsHow to check the type of a unit test value using Jest?
I have a function that returns an object with two properties: name and id, where name will receive its value per parameter and id is generated automatically by Date.now(). My goal is to create a…
-
1
votes1
answer39
viewsWhy specify a number of assertions explicitly in my test?
I started studying unit tests with Jest, but I didn’t really understand the use of expect.assertions when testing with Javascript. Let’s consider the example given below by the Jest documentation…
-
1
votes1
answer67
viewsHow do I test integration with mock from React?
I want to test the following component but I don’t know how to use jest mocks in case of a request with Axios. Component: import React, { useEffect, useContext } from 'react' import {…
-
1
votes0
answers23
viewsHow to test a "await import" with Jest in Typescript
I have an api that in the file that imports the routes to then link them to the express app I use fast-glob to search for files with the extension *.route.ts and then import these methods, like…
-
1
votes1
answer37
viewsHow to create a test for a screen that uses the same hook multiple times? React Testing Library
I came across a test scenario in React where I need to hook twice. In this case I am using a hook called useGet() in two situations on the same page. Of all the times I have tried only the last…
-
1
votes1
answer765
viewsTypeerror: Cannot destructure Property `name` of 'Undefined' or 'null'
I’m using jest along with supertest to test my application endpoints. The tests with the get requests are working, but the test with the post request is giving error: clientRoutes.test.js const…
-
0
votes1
answer82
viewsIgnore Unit test files using jest and webpack
Speak, guys, I’m having a hard time ignoring my test files when I went to build my application. How I set up the Web Pack to ignore test files?
-
0
votes0
answers78
viewsTest functions with Jest and Enzyme?
How can I test this function with Jest and Enzyme? addProducts = id => { toast.success("Product added", { position: toast.POSITION.TOP_RIGHT }); history.push(`/product/${id}`); }; I was using…
-
0
votes1
answer275
viewsHelp with jest ERROR : 'Test suite failed to runReferenceError: regeneratorRuntime is not defined'
I’m starting in TDD, I’m using jest to learn. But I have a question: I’m testing the following code : export const search = (query, type) => { return…
-
0
votes1
answer608
viewsJest integration test - Nodejs API + Mongo
I would like a help in my tests, because I am doing something wrong because there is time that my test passes and soon after it does not pass more. Below are some of the two tests I have of my study…
-
0
votes0
answers10
viewsEnzyme - Check whether a function of a Functional Component has been called
I have an React project that had unit tests with Jest and Enzyme. Inside the component I want to create a unit test, I need to know if an internal function (myFunction in the example below) of the…
-
0
votes0
answers116
viewsHow to test prop update in Reactjs
I created a component Button which has a function onClick and a prop disabled. The function defines a state isLoading as true, and prop receives the value of this state, that is, while the page is…
-
0
votes0
answers105
viewsUnit tests with JEST, on Node.Js, without using module.Exports in Javascript code files
With both files below (ePar.js and ePar.test.js) in the same folder, how to perform the unit test, with the JEST, via Node.Js, of function ePar (in the archive ePar.js) WITHOUT ALTERING THE SAME? I…
-
0
votes1
answer80
viewsTesting a cron-job with JEST
I have a javascript class that contains a function which initializes a cron job. To perform cron-job I used the Node-Cron library. But I can’t find a way to test the class and function. The…
-
0
votes1
answer214
viewsTest error with Jest and Supertest
Good afternoon, you guys; I created my tests with Jest and supertest, and they are giving an error "Object.is Equality", Versão Node: 12.18.3 Versão NPM: 6.14.4 Versão Yarn: 1.22.4 ps: I am using…
-
0
votes0
answers64
viewsts-jest (typescript Compiler) [...]. default is not a constructor
i’m trying to use ts-jest in a Vue project to Transform some ". ts" files in "js" so jest can test them. My problem is: typescript Compiler Give me this error: _className.default is not a…
-
0
votes0
answers13
viewsHow to mock part of a context in React
Hello I have the following context: import React from 'react' const AuthContext = React.createContext({ isAuth: false, login: f => f, logoff: f => f }) const AuthProvider = ({ children })…
jestasked 4 years, 1 month ago LeandroLuk 4,989 -
0
votes0
answers13
viewsRecord the fastfycookie module in nestjs tests
Good morning, I am using nestjs to develop an api, Nest is already integrated with jest, I need to register the fastfycookie module in the test module as well as it is registered in Mains.ts…
-
0
votes1
answer199
viewsJest gives error: "Typeerror: expect(...). toHaveStyle is not a Function"
I’m trying to use jest to test the style of a component, and it’s giving me this error: "TypeError: expect(...).toHaveStyle is not a function" It is a simple component I created only with…
-
0
votes0
answers21
viewsHow to force jest not to run tests on interfaces in Typescript
Hello, I have a project built in Typescript and in it I am using Jest (ts-jest) to do the tests. While running jest with the command --coverage realized that it is passing over lines of code that…
-
0
votes0
answers38
viewsHow to test a saga function by mocking a generating function?
So far I haven’t found an efficient way to test the sagas of my "start" function with the redux-saga-test-plan along with Jest. I already tried to fuck the function fluxo, but I did not succeed. My…
-
0
votes0
answers30
viewsHow to test a 500 status with Jest in Expressjs
I have an application where I am trying to create a simple test to improve code coverage. I currently have a route that returns a health check, like this: import { Express, Request, Response, Router…
-
0
votes0
answers18
viewsjest mockImplementation does not work in React navigation (React Nactivate)
I have the following code: jest.mock('@react-navigation/native', () => { return { useNavigation: mockedNavigation, }; }); ... it('should pass the test', async () => {…
-
0
votes0
answers15
viewsHow to test an element using Compose?
const enhance = compose( mapStateToProps, withRouter, withApollo ) export default enhance(ManagePublicTable) In the archive Managepublictable.spec.js I’m importing the component as: import {…
-
0
votes0
answers14
viewsTDD with Jest and sequelize - POSTGRES Migration error for SQLITE
I am implementing TDD with Jest in a Node with express application, my database is POSTGRES and I have several sequelize Migrations already configured, and for my test scenarios I am running these…
-
0
votes0
answers16
views--findRelatedTests does not work
I’m trying to use the --findRelatedTests to run pre-commit tests using lint-staged, but the following error always happens The --findRelatedTests option requires file paths to be specified. Example…
-
-1
votes0
answers36
viewssingle tests on Ode with jest doubt expect
What should I put on expect to check if the product has been deleted once it returns nothing? it('should be able to delete a product.', async () => { const product = await…
-
-1
votes1
answer52
viewsError testing Activatedroute with angular jest 9
First thank you for reading my question! Setting: I’m testing an angular 9 application with jest of a component using a solver class'. I tried to set up a mock to resolve it, but when running tests…
-
-1
votes1
answer465
viewsSettings Jest + Mongodb
I am studying jest and stuck in a part in the course where it is made the configuration of the project to run the jest next to the mongodb. I’m using the dependency @Shelf/jest-mongodb.…
-
-1
votes1
answer86
viewsHow to mock a constant object in Jest
Hello I have got a constant file set like this in an React project: src/constants/env.ts export default { PROD: ['prod', 'production'].includes((process.env.NODE_ENV || '').toLowerCase()) } This…
-
-1
votes1
answer58
viewsTreatment of negative test cases with JEST
I have a Code Jest who should test a business rule that says: No client must have an invalid CPF it(" should not be able to create a new user whith a wrong CPF",async()=>{ const repositoryFake =…
-
-1
votes0
answers7
viewsHow to get token via test with jest
I’ve been having trouble finding a solution when developing automated testing with Facebook jest when it comes to getting token to test authentication. With this code does not return the token. But…
-
-1
votes0
answers8
viewsasynchronous import to jest.mock to keep the simulation file separate and reusable for other tests
I am trying to make an import into my play simulation to use a separate file to play the same simulation in multiple codes. Simulation below: const listCache: Array = []; jest.mock('aws-sdk', ()…