forked from MetaMask/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.ts
More file actions
34 lines (27 loc) · 1.04 KB
/
Copy pathindex.test.ts
File metadata and controls
34 lines (27 loc) · 1.04 KB
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
import cli from './cli';
import { commands } from './commands';
jest.mock('./cli');
describe('create-package/index', () => {
let originalProcess: typeof globalThis.process;
beforeEach(() => {
originalProcess = globalThis.process;
// TODO: Replace with `jest.replaceProperty` after Jest v29 update.
globalThis.process = { ...globalThis.process };
});
afterEach(() => {
globalThis.process = originalProcess;
});
it('executes the CLI application', async () => {
const mock = cli as jest.MockedFunction<typeof cli>;
mock.mockRejectedValue('foo');
jest.spyOn(console, 'error').mockImplementation();
// eslint-disable-next-line @typescript-eslint/no-require-imports, n/global-require
require('.');
await new Promise((resolve) => setImmediate(resolve));
expect(cli).toHaveBeenCalledTimes(1);
expect(cli).toHaveBeenCalledWith(process.argv, commands);
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith('foo');
expect(process.exitCode).toBe(1);
});
});