Category "jestjs"

Number Matcher Error even though values are of type Number

I am having trouble with the third test case in my describe case. More specifically, I get the error with the line expect(secondResult._body.length).toHaveLengt

NestJS cookie-parser is not a function error during e2e test

I have tried to add cookie-parser - https://www.npmjs.com/package/cookie-parser to my NestJS app: import * as cookieParser from 'cookie-parser'; consumer .appl

How to debug Jest Tests when using Yarn 2 / Yarn PnP

I'd like to use the node --debug-brk feature described in a previous answer and the jest docs to debug in npm/yarn 1 based projects, but node_modules/ is not pr

How to mock uuid with Jest

so on my search for an answer to my problem I found this post: Jest: How to globally mock node-uuid (or any other imported module) I already tried the answer b

@react-native-firebase breaking unit tests

I installed v6 of @react-native-firebase, it's working as expected but when I try to run a unit test I get the following error: Jest encountered an unexpected

Jest Cannot read property 'createEvent' of null

I was trying to mock rejected value and got this error. It's weird that this construction works in the case of "success" addUser.mockImplementation(value =>

Unexpected token 'import' error while running Jest tests?

I realize this question has been asked several times but all of the solutions I've come across don't seem to work for me. I'm running into the following error w

How to do Parameter Validation while using aws-sdk-mock

I am using aws-sdk-mock with Jest for testing AWS Lamda. My lambda uses AWS Polly Service to convert text to speech. Following is the piece of code which I want

How to mock react custom hook returned value?

Here is my custom hook: export function useClientRect() { const [scrollH, setScrollH] = useState(0); const [clientH, setClientH] = useState(0); c

How to pass in the done() parameter on an async jest test.each case

I'm trying write a jest test case that tests an async method, I want to pass in the done() parameter so jest waits for it to be fired before it ends the test, h

Testing functions with arguments in React with Jest Enzyme

I have a function named toggleFilter() in a react component which looks like this: toggleFilter = (filterType, filterName) => { const filterApplied

"istanbul ignore next" command seems to be ignored

I'm trying to use Jest to test my code. It was working quite fine until I tried to exclude a class method from the tests. The querySelector() call is the reason

aws cdk 2.0 init app fails to build with prettier issues, which is from jest-snapshot

node: v16.7.0cdk: 2.0.0 (build 4b6ce31) package.json: "devDependencies": { "@types/jest": "^26.0.10", "@types/node": "10.17.27", "aws-cdk": "2.0.0

override injection token in unit test

I have a simple service with an Injection token that is used to provide some kind of configuration for the service. It's all working as expected. Although I was

How to use Jest useFakeTimers with RXJS?

My application is primarily using React Redux. We have a few places that use RXJS to simplify things. I just started using jest.useFakeTimers. I realized that g

Run Jasmine tests (coupled to DOM/jquery etc) via command line for CI

We have a set of Jasmine tests that run successfully in the local web server. http-server. We would like to run these tests from the command line during the

How to mock and check that a function from a library in Jest framework?

I have a button with "Download" text on it defined in ReactJS code. Now, I want to write a unit test to check that this function is getting called when this but

Mocking react-router-dom hooks using jest is not working

I'm using Enzyme's shallow method to test a component which uses the useParams hook to get an ID from the URL params. I'm trying to mock the useParams hook so

react-query how to call mutate from custom useMutation hook in Jest test

I'm running a React Native project where I'm testing custom hooks written with react-query. I'm using Jest, @testing-library/react-hooks and @testing-library/re

Testing MutationObserver with Jest

I wrote a script with the main purpose of adding new elements to some table's cells. The test is done with something like that: document.body.innerHTML = ` &l