Category "jestjs"

Mock addListener from navigation in unit test

Used addListener from navigation like this, useEffect(() => { const navigationSubscription = props.navigation.addListener( "willFocus", () => setFo

CRA - Jest mock loses the mock implementation

I'm trying to use __mocks__. src/shared/state/use-some-state.ts export const useSomeState = () => { return { value: 6 }; } which is exported from an index

HTTP POST request test is not getting passed

I wrote some nodejs codes to be evaluated by a particular test file, candidate.test.js but surprisingly the test keeps failing. Below is the error I am getting:

How to create a test Unit method for a get request that fetches Data from Database(MongoDB)?

Get request method in tasks.js file const { Task } = require('../model/Tasks.js') const asyncWrapper =require('../middleware/async') const getTask = asyncWrapp

Is there an equivalent tool like ruby-prof for node.js?

I want to profile a Jest test, but I only want to see the behavior for some specific methods. In ruby, I can do that with ruby-prof, but is there an equivalent

ReferenceError: window is not defined, consider using the "jsdom" test environment (jest V28)

I would like some assistance in resolving this error. Am using Jest V28.0.0. Here's how my package.json's test script & devDependencies look like "scri

Jest: Unexpected value 'NgxsRootModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation

I'm getting the following error when running a test in Jest, using Angular 13: Unexpected value 'NgxsRootModule' imported by the module 'DynamicTestModule'. Pl

Nestjs unit test: TypeError: this.userModel.findById(...).exec is not a function

using nestjs framework and with a repository class that uses mongoose to do the CRUD operations we have a simple users.repository.ts file like this: @Injectable

CRA - window object is undefined - jest/react

I have an issue in my tests that flag up a window variable as undefined. But I don't know where in the setupTests.tsx, I would need to define it. So far the var

Jest: How to transform import.meta.url using Next 12 with SWC

I am using Jest in a Next.js 12 App with the Rust Compiler. Since I'm using WebWorkers I have a file in which I use import.meta.url. to construct the worker The

React Testing Library gives console error for ReactDOM.render in React 18

After updating to React 18 or creating a new React 18 app from create-react-app, when I run the yarn test command, it gives a console.error as a Warning for eac

React Testing Library with userEvent.click wrong act() warning

I have several tests written with Jest and React Testing Library. They all mock fetch and use a userEvent.click call to fire a submit button which makes a fetch

Error message TypeError: this.subQuery is not a function appears

If I run the tests with jest, I got always the error message TypeError: this.subQuery is not a function with a reference on the marked line in the testModelDb.t

Upgrading Jest to v28 - Error Test environment jest-environment-jsdom cannot be found

Has anyone successfully upgraded to latest Jest version 28.0.0? I'm receiving an error: Error: Test environment jest-environment-jsdom cannot be found. Make sur

Sorry, name can only contain URL-friendly characters. Error - for NPM Install Jest

Hello I am not sure what is wrong with installing Jest. https://jestjs.io/docs/getting-started But here is my issue with my terminal. Please help. I am new to t

How to test scrollHeight, scrollWidth, clientHeight and clientWidth with react-testing-library and jest

I just can't figure out, how I'm supposed to mock / get data from scrollHeight, scrollWidth, clientHeight and clientWidth in test. For better introduction, my t

Configuring Jest with Rollup and Typescript

I created an app within a monorepo (Lerna) using yarn workspace. The architecture of the app is as follow: my-monorepo ├── node_modules ├

The current testing environment is not configured to support act(...) - @testing-library/react

I'm trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-

Swiper 8 and jest

Swiper 8 and Jest (support ESM) Must use import to load ES Module enter image description here enter image description here How we can solve if I need to keep s

Running a for loop within a Puppeteer test

I'm trying to run a for loop within a Puppeteer test that sends values to a search bar: test('test one', () => { var results = [""] var fuzz = ['ap