Jest test fails with Unexpected token, expected ";"

Issue I have a Node project using Typescript and Jest. Currently I have this project structure With this tsconfig.json file “compilerOptions”: { “target”: “ES2017”, “module”: “commonjs”, “allowJs”: true, “outDir”: “dist”, “rootDir”: “src”, “strict”: true, “moduleResolution”: “node”, “esModuleInterop”: true } this

Continue reading

Jest test assertion, expect a nested object

Issue When I do the below expect in jest with native test expect(mockOnChange).toHaveBeenCalledWith({ order_type: expect.arrayContaining([‘1’]), number: ”, ouser_ids: expect.arrayContaining([‘user_id1’]), payment_type: expect.arrayContaining([‘2’]), start_date: old_Date, end_date: current_date, state: ‘all’, }); I’m getting the following error Object { "end_date": "2022/06/07", "number": "", –

Continue reading

Test unable to run test cases exits with TypeError: Jest: a transform must export a `process` function

Issue { //tsconfig.base.json "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "typeRoots": ["node_modules/@types"], "lib": ["es2018", "dom"] }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true }

Continue reading

tsconfig problems with test and compiling

Issue This is my tsconfig.json { "compilerOptions": { "noImplicitAny": true, "declaration": false, "strict": true, "strictNullChecks": false, "target": "ES2019", "module": "commonjs", "resolveJsonModule": true, "allowJs": true, "checkJs": false, "outDir": "dist", "esModuleInterop": true, "inlineSourceMap": true, "rootDir": "./", "baseUrl": "./", "typeRoots": [ "./node_modules/@types" ],

Continue reading

Jest Spy not being called

Issue I am trying to run a test using the winston logger package. I want to spy on the createlogger function and assert that it is being called with the correct argument. Logger.test.ts import { describe, expect, it, jest, beforeEach,

Continue reading

Jest/Rxjs – timeout when calling for subscription from a getter

Issue I have a service that updates an Rxjs Subject whenever a method in the service is called: @Injectable() export class AppAlertService implements IAppAlertService { private readonly _alertBehaviourSubject: Subject<IAlertConfiguration> = new Subject<IAlertConfiguration>(); public get alertConfiguration(): Observable<IAlertConfiguration> { return this._alertBehaviourSubject.asObservable(); }

Continue reading

How to test a http request function in a service with Angular and Jest

Issue I created a simple service returning a json object. getCountries() { return this.httpService.get(‘../../assets/countries.json’); } The test describe(‘TestServiceService’, () => { let service: TestServiceService; let httpController: HttpTestingController; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule] }); httpController = TestBed.inject(HttpTestingController); service = TestBed.inject(TestServiceService);

Continue reading

Watch and rerun Jest JS tests

Issue The Jest documentation suggests using npm test to execute tests. Is there a way of watching your source and tests to rerun Jest tests automatically when relevant files have been changed? Solution Thanks to Erin Stanfill for pointing out,

Continue reading

Testing with 'toHaveStyle' passes when expecting fail

Issue I’m learning about testing and react. I’m having a little trouble understanding why a test is passing when it should not: From App.js <button style={{backgroundColor: ‘gray’}}> Gray button </button> From App.test.js expect(colorButton).toHaveStyle( {backgroundColor: ‘gray’ }); // passes ok expect(colorButton).toHaveStyle(

Continue reading

How to mock AxiosInstance?

Issue I have axios with following HttpClient class export default class HttpClient { constructor(baseUrl: string) { const axiosInstance = axios.create({ validateStatus(status: number) { return status === 200 || status === 201; }, }); axiosInstance.interceptors.request.use((config) => { if (AuthUtil.getAuthHeader()) config.headers =

Continue reading

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

Issue node: v16.7.0 cdk: 2.0.0 (build 4b6ce31) package.json: "devDependencies": { "@types/jest": "^26.0.10", "@types/node": "10.17.27", "aws-cdk": "2.0.0", "jest": "^26.4.2", "ts-jest": "^26.2.0", "ts-node": "^9.0.0", "typescript": "^3.9.7" }, "dependencies": { "aws-cdk-lib": "2.0.0", "constructs": "^10.0.0", "source-map-support": "^0.5.16" } npm run build/watch stack trace: node_modules/@types/prettier/index.d.ts:41:54

Continue reading

Query a simple button with jest and

Issue I’m trying to test my component, so here it’s : import React from ‘react’; import { useNavigate } from ‘react-router-dom’; import ‘../styles/mainPageStyles.css’; const MainPage = (): React.ReactElement => { const navigate = useNavigate(); const handleBeginQuiz = () => {

Continue reading

How to test NestJs response interceptor

Issue I tried to follow this thread but it I keep getting an error. transform-response.interceptor.ts: import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from ‘@nestjs/common’; import { Observable } from ‘rxjs’; import { map } from ‘rxjs/operators’; import { ApiResponseInterface }

Continue reading

Query a simple button with jest and

Issue I’m trying to test my component, so here it’s : import React from ‘react’; import { useNavigate } from ‘react-router-dom’; import ‘../styles/mainPageStyles.css’; const MainPage = (): React.ReactElement => { const navigate = useNavigate(); const handleBeginQuiz = () => {

Continue reading

How to test NestJs response interceptor

Issue I tried to follow this thread but it I keep getting an error. transform-response.interceptor.ts: import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from ‘@nestjs/common’; import { Observable } from ‘rxjs’; import { map } from ‘rxjs/operators’; import { ApiResponseInterface }

Continue reading

Uncaught TypeError: Cannot read properties of undefined (reading 'isBatchingLegacy')

Issue I am trying to test a react typescript project using jest but it’s giving a confusing error: Error image Here is my package.json: "dependencies": { "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^12.1.5", "@testing-library/user-event": "^13.5.0", "@types/jest": "^27.4.1", "@types/node": "^16.11.26", "@types/react": "^17.0.43", "@types/react-dom": "^17.0.14",

Continue reading

TS-Jest not resolving tsconfig paths

Issue I have already added these paths to tsconfig.json: { "compilerOptions": { "lib": ["ESNext"], "moduleResolution": "node", "noUnusedLocals": true, "noUnusedParameters": true, "removeComments": true, "sourceMap": true, "target": "ES2020", "outDir": "lib", "emitDecoratorMetadata": true, "experimentalDecorators": true, "baseUrl": ".", "paths": { "@lambdas/*": ["src/lambdas/*"], "@services/*": ["src/services/*"],

Continue reading