github-pages-deploy-action/__tests__/worktree.error.test.ts
Lucas dos Santos Abreu 460c7b8081
fix issue #866 - upgrading to typescript 4.4.3 (#896)
* Bump typescript from 4.3.5 to 4.4.3

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.5 to 4.4.3.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.3.5...v4.4.3)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* (fix): extract error message

* (fix): error is unknown on __tests__

* (fix): add cover

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-06 23:20:55 +01:00

37 lines
984 B
TypeScript

import {TestFlag} from '../src/constants'
import {execute} from '../src/execute'
import {generateWorktree} from '../src/worktree'
jest.mock('../src/execute', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
execute: jest.fn()
}))
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 ❌'
)
}
})
})