Testing debounced function in React component with Jest and Enzyme

I am testing a React component using Jest and Enzyme, and am having difficulty testing that a debounced function is called properly (or at all). I’ve simplified the component code below (edited to …

Remove logging the origin line in Jest

Jest has this feature to log the line that outputs to console methods. In some cases, this can become annoying: console.log _modules/log.js:37 ℹ login.0 screenshot start console.time _modules/…

How to determine if JEST is running the code or not?

I am creating a JS test on my react-native project. I’m specifically using firebase for react native, in which I would like to replace firebase instance with a mockfirebase instance if JS is running the code of my class. For example I have class setup like below. I’d like to have a check if jest is the running environment then I’d replace the import line with appropriate mock class. Answer jest sets an environment variable called JEST_WORKER_ID so you check if this is set: I also see that if NODE_ENV is not set the jest CLI sets it to the

command not found: jest

I have a test file like so: (I am using create-react-app) import React from ‘react’; import ReactDOM from ‘react-dom’; import App from ‘./components/Calculator’; import { getAction, getResult } from …

Mock a dependency’s constructor Jest

I’m a newbie to Jest. I’ve managed to mock my own stuff, but seem to be stuck mocking a module. Specifically constructors. usage.js const AWS = require(“aws-sdk”) cw = new AWS.CloudWatch({apiVersion:…

Getting `TypeError: jest.fn is not a function`

I’m trying to create the following unit test using Jest. jest.dontMock(“pointsAwardingActions.js”); describe(“points awarding actions”, () => { describe(“award points&…

How to mock Push notification native module in React native jest tests?

When using the module react-native-push-notification, I had this error: I tried to mock the module by creating __mocks__/react-native.js and putting this code within it: Now, I have this error: How I could mock fully this module the right way? Answer I mocked the module PushNotificationIOS by creating a setup file jest/setup.js: I’ve configured jest to run this setup file by adding this line into packages.json:

How can I get the arguments called in jest mock function?

How can I get the arguments called in jest mock function? I want to inspect the object that is passed as argument.

Components using Date objects produce different snapshots in different timezones

I’m using Enzyme with enzyme-to-json to do Jest snapshot testing of my React components. I’m testing shallow snapshots of a DateRange component that renders a display field with the current range (e.g….