-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdidNotReceive.spec.ts
More file actions
52 lines (41 loc) · 2.08 KB
/
didNotReceive.spec.ts
File metadata and controls
52 lines (41 loc) · 2.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import test from 'ava'
import { Substitute, Arg } from '../../src'
import { SubstituteException } from '../../src/internals/SubstituteException'
interface Calculator {
add(a: number, b: number): number
subtract(a: number, b: number): number
divide(a: number, b: number): number
isEnabled: boolean
}
test('not calling a method correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()
calculator.didNotReceive().add(1, 1)
t.throws(() => calculator.received().add(1, 1), { instanceOf: SubstituteException })
t.throws(() => calculator.received().add(Arg.all()), { instanceOf: SubstituteException })
})
test('not getting a property correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()
calculator.didNotReceive().isEnabled
t.throws(() => calculator.received(1).isEnabled, { instanceOf: SubstituteException })
t.throws(() => calculator.received().isEnabled, { instanceOf: SubstituteException })
})
test('not setting a property correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()
calculator.didNotReceive().isEnabled = true
t.throws(() => calculator.received(1).isEnabled = true, { instanceOf: SubstituteException })
t.throws(() => calculator.received().isEnabled = true, { instanceOf: SubstituteException })
})
test('not calling a method with mock correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()
calculator.add(1, 1).returns(2)
calculator.didNotReceive().add(1, 1)
t.throws(() => calculator.received(1).add(1, 1), { instanceOf: SubstituteException })
t.throws(() => calculator.received().add(Arg.all()), { instanceOf: SubstituteException })
})
test('not getting a property with mock correctly asserts the call count', t => {
const calculator = Substitute.for<Calculator>()
calculator.isEnabled.returns(true)
calculator.didNotReceive().isEnabled
t.throws(() => calculator.received(1).isEnabled, { instanceOf: SubstituteException })
t.throws(() => calculator.received().isEnabled, { instanceOf: SubstituteException })
})