-
Notifications
You must be signed in to change notification settings - Fork 542
/
evalHandler.test.ts
37 lines (29 loc) · 1.04 KB
/
evalHandler.test.ts
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
import { evalBundle } from '@metamask/snaps-utils';
import { YargsArgs } from '../../types/yargs';
import { evalHandler } from './evalHandler';
jest.mock('@metamask/snaps-utils', () => ({
...jest.requireActual('@metamask/snaps-utils'),
evalBundle: jest.fn(),
}));
const getMockArgv = ({ bundle = 'bundle.js' } = {}) => {
return { bundle } as unknown as YargsArgs;
};
const evalBundleMock = evalBundle as jest.MockedFunction<typeof evalBundle>;
describe('evalHandler', () => {
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => undefined);
jest.spyOn(console, 'error').mockImplementation(() => undefined);
});
it('evaluates a bundle', async () => {
await evalHandler(getMockArgv());
expect(console.log).toHaveBeenCalledWith(
"Eval Success: evaluated 'bundle.js' in SES!",
);
});
it('logs and throws errors', async () => {
evalBundleMock.mockRejectedValueOnce(new Error('foo'));
await expect(evalHandler(getMockArgv())).rejects.toThrow(
'Snap evaluation error: foo',
);
});
});