From d748e8160d887b975fa1b15a64cf23d8bc707fa9 Mon Sep 17 00:00:00 2001 From: Hien Pham Date: Thu, 25 Jun 2026 21:01:45 +0300 Subject: [PATCH] docs: clear mock after each test and refine expectation for tax calculator call - We need to clear the mock between different assertions - We have either toHaveBeenCalledOnce or toHaveBeenCalledExactlyOnceWith matcher --- adev/src/content/guide/testing/services.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adev/src/content/guide/testing/services.md b/adev/src/content/guide/testing/services.md index 1da612b18fd..99ea1282999 100644 --- a/adev/src/content/guide/testing/services.md +++ b/adev/src/content/guide/testing/services.md @@ -151,6 +151,10 @@ describe('OrderTotal', () => { service = TestBed.inject(OrderTotal); }); + afterEach(() => { + taxCalculatorStub.calculate.mockClear(); + }); + it('adds tax to the subtotal', () => { expect(service.total(100)).toBe(105); }); @@ -158,7 +162,7 @@ describe('OrderTotal', () => { // Verify the interaction with a spy it('calls the tax calculator', () => { service.total(100); - expect(taxCalculatorStub.calculate).toHaveBeenCalledExactlyOnce(); + expect(taxCalculatorStub.calculate).toHaveBeenCalledExactlyOnceWith(100); }); }); ```