/
hook.spec.js
44 lines (35 loc) 路 1.14 KB
/
hook.spec.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
import fs from 'fs'
import hook from '@commands/hook'
import hookConfig from '@commands/hook/hook'
import getAbsoluteHooksPath from '@utils/getAbsoluteHooksPath'
import * as stubs from './stubs'
jest.mock('@utils/getAbsoluteHooksPath')
describe('hook command', () => {
beforeAll(() => {
getAbsoluteHooksPath.mockResolvedValue(stubs.hooksPath)
})
it('should match hook module export', () => {
expect(hook).toMatchSnapshot()
})
it('should match hook configuration', () => {
expect(hookConfig).toMatchSnapshot()
})
describe('create hook', () => {
it('should create the hook file', async () => {
await hook.create()
expect(getAbsoluteHooksPath).toHaveBeenCalledWith(hookConfig.FILENAME)
expect(fs.writeFileSync).toHaveBeenCalledWith(
stubs.hooksPath,
hookConfig.CONTENTS,
{ mode: hookConfig.PERMISSIONS }
)
})
})
describe('remove hook', () => {
it('should remove the hook file', async () => {
await hook.remove()
expect(getAbsoluteHooksPath).toHaveBeenCalledWith(hookConfig.FILENAME)
expect(fs.unlinkSync).toHaveBeenCalledWith(stubs.hooksPath)
})
})
})