Category "jestjs"

How do you test a form upon the submission addEventListener with jest without a framework only vanilla JS

Most of the research I have done in regards to jest testing unit testing and/or integration testing is all heavily geared towards React. But I am not using reac

jest supertest with express-session

I want to test my routes with jest but I don't know how to mock or simulate a session in my test to pass the first if line 2 app.get('/getMailSuiviList', (req,

Jest test does not find provided route

Started working on a new application and decided to write tests from very early stage to avoid any future mistakes. However, little bit struggling I guess with

Test react custom hook with mocking blob response

I have a created a hook as following: import { AxiosResponse } from 'axios'; import { DEFAULT_EXPORT_FILE_NAME } from 'constants'; import { useRef, useState } f

Running a single test in WebStorm using Jest

I'm trying to run single test in my project. However every time I use triangle run icon WebStorm creates new configuration for me. I'm adding screenshots to cla

Unexpected Jest Errors when Mocking Uppy

I'm attempting to mock the Uppy class from the uppy package in a Jest unit test following guidance from this previously answered question. My failing code is be

Jest tests breaks when calling getState outside a component in React

A bunch of my tests suddenly started breaking when I use store.getState() inside a function in React. If I log the store, the store exists but it is still break

Cannot get React testing Jest-DOM to select a date from a date picker or time from a time picker

I cannot, for the life of me, figure out how to get Jest-dom in react testing to select a date picker and the same for the time picker. All my other fields are

Error in Jest Test with Vanilla Javascript: expect(jest.fn()).toBeCalledWith(...expected) Expected: "click", Any<Function> Number of calls: 0

Looks like click method is not getting triggered I have tried evreything, it would be appreciated if someone knows the answer I'm getting this error: expect(jes

Updating create-react-app to latest version breaks async tests

I have an issue, I have recently upgraded my version of react to use react-script version 5.0.1 from version 4.0.3. Doing the instructions as per https://github

JEST: My Isolated module function depends on a function found on the same module. After mocking, it still relies on the original implementation

I have abc.js const a = (a)=>{ return (b(a) + 1) } const b = (num)=>{ return(num + 1) } module.exports = { a, b } When I do my test for

MongoDb can't use types in jest - declares ... locally, but it is not exported

I use the mongodb library in TypeScript for a few functions (e.g. lambda functions but that should not matter). The imports look like that: import { ObjectId, D

Babel doesn't ignore snapshot folder and files

I'm using the following npm build script with Babel 7; "build": "rm -rf dist && babel src/lib --out-dir dist --copy-files --no-copy-ignored", And this

node + ts-jest + ESM, jest.mock doing nothing

I am using ts-jest with ESM imports on nodejs. The problem is that my jest.mock is not working, it is not mocking. import { jest } from "@jest/globals"; jest.m

Mock Injected Twilio Service in Unit Testing Nest.js

I have a problem with overriding provider/setup module testing in nest.js application for testing. Module file: smsModule.ts: import { TwilioService } from './t

jest TypeError: Cannot read property 'createRef' of undefined

ImageSlider.tsx const ImageSlider = (props: INF_ImageSlider) => { const [idx, setIdx] = useState(0); const imgRef = React.createRef<HTMLImageEleme

How to Unit Test a method inside a module in NestJs (Jest)

I'm adding tests on a project and improving coverage. I would like to know how can I test a method defined inside a module definition in NestJs. import { Middle

Jest Testing - mockReset does not clear the already set values

I have a lambda which calls an interface. Am trying to mock the functions imported from the interface. In each test case, I have to mock different values. When

Can I mock one function exported from a typescript module that uses ES6 import style

I have been struggling with some specific ES6 importing-style and using with Jest mocking in typescript. It's very specific, so I wrote this example puzzle to

React/Jest - How to simulate touch "swipe" event

I have a component that triggers a function call whenever a swipe interaction was done. This swipe interaction can either be executed by touchEvent or mouseEven