>

CODEMASTERYLAB

IDE PLATFORM
CoursesCommunity BlogsKnowledge GraphQuizzesInterview Prep

Sign in to track progress & earn XP

Sign In Create Account
>
Code Mastery Lab

Code Mastery Lab

Sign In

Testing Services — Mocking HTTP and Isolating Dependencies

Question 1 / 1

0:00
Core
Medium

A test subscribes to service.getOrders(), calls httpMock.expectOne(url), flushes a response, then asserts on the result. The test passes. In afterEach, httpMock.verify() is called. The service actually makes two HTTP requests — one to /orders and one to /users/me on every call. What happens when verify() runs?

typescript it('fetches orders', () => { let result: Order[]; service.getOrders().subscribe(o => result = o);

const req = httpMock.expectOne('https://api.myapp.com/v2/orders'); req.flush(fakeOrders);

expect(result.length).toBe(2); // passes });

afterEach(() => httpMock.verify());