Category "jestjs"

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

Jest test error: ...subscribe is not a function

I'm using Jest to test my Angular app (using Nx workspaces). I have a component that uses a service that I'm trying to mock. Here's the code: myDummyService.per

Test functions cannot both take a 'done' callback

I'm trying to create a simple test with nestjs, and I'm get this error Test functions cannot both take a 'done' callback and return something. Either use a 'do

NestJs e2e returns 201 created response though required form data is missing, expected 400 bad request

I'm trying to write a test that checks if request body does not have proper data, it should return an error, and the status code should be 400. Which I think is

Why does jest mock test give me undefined?

I am new to learning jest mocks. I am trying out a very simple test. I have a folder greeter. This folder has a file 'greeter.js' and a subfolder called 'test'.

TypeError: _API.default is not a constructor with Jest tests

I have an API class that I am trying to use in a React app. // API file class API { ... } export default API; // Other file import API from "utils/API"; con

Express Route Testing - req.parameter

How would one test an express route such as app.get('/myapp/:parameter') How would I use jest to test that no parameter was passed? I have an error that will re

Cannot find module '@babel/runtime/helpers/interopRequireDefault' from 'node_modules/react-native/jest/setup.js' when I run tests

I'm trying to build a mobile application with typescript, react-native, expo and jest. When I'm trying to run tests: FAIL src/components/Button/tests/Button.t

react testing library: can't acquire context from the given item

I have this component, which uses react-chartjs-2 to render a Doughnut chart: const CompliancyChart = ({data}): JSX.Element => { ... return ( <Cha

supertest gets timeout error when I use await in a controller

const express = require('express'); const router = express.Router(); const Product = require('./../model/product'); router .route('/api/product') .get(async

Jest test passes but .. has console message You are trying to access a property or method of the Jest environment after it has been torn down

My test passes but has a console refrenceError: You are trying to access a property or method of the Jest environment after it has been torn down. Test: import

Mocking a function in jest which returns Promise<string[] | never>

I'm using React+JEST to test an existing component. It has a function filterDeliveries like so : const filterEmptyDeliveries = (arr): Promise<string[] | neve

Jest test sometimes fails (DynamoDB integration tests)

I have Serverless application (node:14.19.1-bullseye-slim) with almost 400 tests. There are mostly functional tests with using of local DynamoDb. The problem is