-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme.test.js
46 lines (41 loc) · 1.19 KB
/
readme.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
42
43
44
45
46
const extendJestWithShellMatchers = require('./index')
beforeAll(() => {
extendJestWithShellMatchers()
})
describe('README.md', () => {
it('should test the output from a spawned process', async () => {
const input = ['sh', ['./hello-world.sh']]
const expectedOutput = {
code: 0,
signal: '',
stdout: 'Hello World\n',
stderr: ''
}
await expect(input).toHaveMatchingSpawnOutput(expectedOutput)
})
it('should mock the date and mkdir commands', async () => {
const date = jest.fn((...input) => {
expect(input).toEqual(['+%m-%d-%Y'])
return {
code: 0,
stdout: '01-06-2019',
stderr: ''
}
})
const mkdir = jest.fn((...input) => {
expect(input).toEqual(['01-06-2019'])
return {
code: 0,
stdout: '',
stderr: ''
}
})
const mocks = { date, mkdir }
const input = ['sh', ['./test-scripts/mkdir.sh'], { mocks }]
await expect(input).toHaveMatchingSpawnOutput(0)
expect(date).toHaveBeenCalledTimes(1)
expect(mkdir).toHaveBeenCalledTimes(1)
expect(date.mock.calls[0]).toEqual(['+%m-%d-%Y'])
expect(mkdir.mock.calls[0]).toEqual(['01-06-2019'])
})
})