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
This commit is contained in:
Hien Pham
2026-06-25 21:01:45 +03:00
committed by Alex Rickabaugh
parent b6dbdcfe34
commit d748e8160d
+5 -1
View File
@@ -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);
});
});
```