-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathclearReceivedCalls.spec.ts
More file actions
28 lines (22 loc) · 870 Bytes
/
clearReceivedCalls.spec.ts
File metadata and controls
28 lines (22 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import test from 'ava'
import { Substitute, SubstituteOf, clearReceivedCalls } from '../../src'
import { SubstituteNode, instance } from '../../src/internals/SubstituteNode'
interface Calculator {
add(a: number, b: number): number
subtract(a: number, b: number): number
divide(a: number, b: number): number
isEnabled: boolean
}
type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
[instance]: SubstituteNode
}
test('clears received calls on a substitute', t => {
const calculator = Substitute.for<Calculator>() as InstanceReturningSubstitute<Calculator>
calculator.add(1, 1)
calculator.add(1, 1).returns(2)
calculator[clearReceivedCalls]();
t.is(calculator[instance].recorder.records.size, 2)
t.is(calculator[instance].recorder.indexedRecords.size, 2)
t.throws(() => calculator.received().add(1, 1))
t.is(2, calculator.add(1, 1))
})