why this test fails while testing my api endpoint?

this error Uncaught exception: Error: listen EADDRINUSE: address already in use :::3000 import supertest from "supertest" import axios from "axios" import app from ".." const request = supertest(app) describe("Test endpoint responses", () => { it("gets the api endpoint", async () => { const response = await request.get("/api/images") expect(response.ok).toBe(false) }) }) >Solution : This means that… Read More why this test fails while testing my api endpoint?

Jest: Explicit Promises Work Differently From Async Test

It seems like the following tests should have the same result: import {render, act} from ‘@testing-library/react’; test(‘async test’, async () => { let component; await act(()=>{ component = render(<div/>); }); console.log("logging"); expect(component).toBeTruthy(); }); test(‘without callback’, () => { let component; act(()=>{ component = render(<div/>); }).then(()=>{ console.log("logging"); expect(component).toBeTruthy(); }); }); with the following package.json: { "dependencies":… Read More Jest: Explicit Promises Work Differently From Async Test

Subscribe function not covered in code coverage jasmine – Angular

I have written unit test cases using karma and jasmine ,everything works fine except whatever code written inside the subscribe block is not covered in code coverage. component.ts function which is testing. updateDocType(uRec, rType) { console.log(uRec) const obj = { vendor_mapping_list: uRec }; const remainingItems = []; const executedItems = []; this.destroySearch$ = this.apiServ.cloneSubscribe(); this.recordStatusMsg… Read More Subscribe function not covered in code coverage jasmine – Angular

Angular test 'subscribe is not a function'

In my component inside ngOnInit I have a subscribe() inside which I call a component function: ngOnInit(): void { this.navigationService.itemReset$.subscribe(event => this.resetItem(event)); } in the navigationService I have: btnPressed$: Subject<Event> = new Subject(); itemReset$: Observable<Event> = this.btnPressed$.asObservable(); keyDown(event: Event): void { this.btnPressed$.next(event); } I searched a lot about this issue, and tried something like this… Read More Angular test 'subscribe is not a function'

Cannot read properties of undefined (reading 'subscribe') of subscribe inside ngOnInit with unit test

Currently facing a unit test errror: AppComponent > should call app TypeError: Cannot read properties of undefined (reading ‘subscribe’) Inside my ngOnInit I have: this.eventsService.currentEvents.subscribe(events => { this.events = events; return this.processEvents(this.events); }); The test where it fails is here (where ngOnInit is called): it(`should call app`, () => { const fixture = TestBed.createComponent(AppComponent); const… Read More Cannot read properties of undefined (reading 'subscribe') of subscribe inside ngOnInit with unit test

Jasmine.createSpy equivalent in jest

I am migrating from jasmine to jest in my application. I have the following line to test JSON.parse(window.document.querySelector(SELECTOR).innerHTML) In my test I used jasmine. document.querySelector = jasmine.createSpy(‘HTML Element’).and.returnValue(dummyEl) But now with jest I get the following error TypeError: Cannot read property ‘innerHTML’ of null Can you help me? >Solution : I think you need a… Read More Jasmine.createSpy equivalent in jest