-
-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathworktree.error.test.ts
More file actions
35 lines (33 loc) · 958 Bytes
/
worktree.error.test.ts
File metadata and controls
35 lines (33 loc) · 958 Bytes
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
import {TestFlag} from '../src/constants.js'
import {execute} from '../src/execute.js'
import {generateWorktree} from '../src/worktree.js'
jest.mock('../src/execute', () => ({
__esModule: true,
execute: jest.fn(() => ({stdout: '', stderr: ''}))
}))
describe('generateWorktree', () => {
it('should catch when a function throws an error', async () => {
;(execute as jest.Mock).mockImplementationOnce(() => {
throw new Error('Mocked throw')
})
try {
await generateWorktree(
{
hostname: 'github.com',
workspace: 'somewhere',
singleCommit: false,
branch: 'gh-pages',
folder: '',
silent: true,
isTest: TestFlag.HAS_CHANGED_FILES
},
'worktree',
true
)
} catch (error) {
expect(error instanceof Error && error.message).toBe(
'There was an error creating the worktree: Mocked throw ❌'
)
}
})
})