forked from testdouble/testdouble-jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtd-mock.test.js
42 lines (33 loc) · 993 Bytes
/
td-mock.test.js
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
let subject
describe('td.replace', () => {
beforeEach(() => {
td.mock('./bar')
td.mock('./baz', () => (() => 'woot'))
td.mock('./qux', () => (() => 'so fake!'), {virtual: true})
td.mock('./quux', () => td.func('quux'), {virtual: true})
subject = require('./foo')
})
it('tdjs will imitate the dep with no-args', () => {
const bar = require('./bar')
td.when(bar(42)).thenReturn('yay!')
const result = subject()
expect(result.bar).toEqual('yay!')
})
it('td.reset() will not pollute stubbings', () => {
const result = subject()
expect(result.bar).toEqual(undefined)
})
it('can pass a factory', () => {
const result = subject()
expect(result.baz).toEqual('woot')
})
it('can pass the virtual option, too', () => {
const result = subject()
expect(result.qux).toEqual('so fake!')
})
it('can assert a call', () => {
const quux = require('./quux')
subject()
td.verify(quux(1337), {times: 1})
})
})