mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Alex Rickabaugh
parent
b6dbdcfe34
commit
d748e8160d
@@ -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);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user