Category "jestjs"

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

Console.log statements output nothing at all in Jest

console.log statements output nothing at all in Jest. This was working for me yesterday, and all of sudden, it's not working today. I have made zero changes to

How to use jest to mock out a private variable

I am trying to write a unit test for a function like this: export class newClass { private service: ServiceToMock; constructor () { this.service =

test case not working for callback setState function

I am calling two APIs using two different function. First, I am fetching order details using getOrder method. Once I get the order, I am calling another method

How to automatic load .feature files

Here is an example of the (react) architecture. src/ components/ Input/ Tests/ Input.feature Input.test.js We test with react testing library and

How do I configure absolute paths for imports in TypeScript based React Native apps?

In order to avoid '../../../../' style relative imports in a TypeScript based React Native app, I would like to configure the app so that I can use absolute imp

Jest finds tests but doesn't collect coverage

I trying to collect test coverage for this project using yarn test --coverage # i.e. "react-scripts test --coverage" My jest config is this: "jest": {

Mock OpenSearch Client in jest unit test

I'm trying to mock out the opensearch client for testing purposes and am running into an error. My app is using OpenSearch (@opensearch-project/opensearch) and

How to mock a single value in a React Context provider while keeping the rest of values

Hi I have a context provider which returns like this: return ( <RepeatsSidebarContext.Provider value={{ loading,

Jest : TypeError: require(...) is not a function

The application is written by React with ES6 so import and export statements are used inside the application. So Jest is configured to work compatible with ES6,

Cannot find name 'it' in Jest TypeScript

I try to create an intial setup for Jest in React + TypeScript. I have completed the initial setup and try to check whether the test runs. When I run the test u

How configure Jest when using react-app-rewired and customize-cra?

I am trying set up tests with Jest in a create-react-app that is using the override function from customize-cra and react-app-rewired. I have set up a relative

Jest - Cannot find module '.../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault'

I am trying to run my project's tests on my CI/CD machines. They are jest tests that have been running fine for some time on all my environments. I am going t

Jest + Material-UI : Correctly mocking useMediaQuery

I'm using Material-UI's useMediaQuery() function in one of my components to determine the size prop to use for a <Button> within the component. I'm tryin