forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.test.js
40 lines (33 loc) · 979 Bytes
/
function.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
global.__dirname = __dirname
jest.mock('fs')
jest.mock('../../../../lib', () => {
return {
...jest.requireActual('../../../../lib'),
generateTemplate: () => '',
}
})
import fs from 'fs'
import '../../../../lib/test'
import { files } from '../../../generate/function/function'
import { tasks } from '../function'
beforeEach(async () => {
fs.__setMockFiles(files({ name: 'sendMail' }))
})
afterEach(() => {
fs.__setMockFiles({})
jest.spyOn(fs, 'unlinkSync').mockClear()
})
test('destroys service files', async () => {
const unlinkSpy = jest.spyOn(fs, 'unlinkSync')
const t = tasks({
componentName: 'service',
filesFn: files,
name: 'sendMail',
})
t.options.renderer = 'silent'
return t.run().then(async () => {
const generatedFiles = Object.keys(files({ name: 'sendMail' }))
expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length)
generatedFiles.forEach((f) => expect(unlinkSpy).toHaveBeenCalledWith(f))
})
})