/
index.test.ts
64 lines (52 loc) · 1.53 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { expect } from '@jest/globals';
import { installSnap } from '@metamask/snaps-jest';
import { NotificationType } from '@metamask/snaps-types';
describe('onRpcRequest', () => {
it('throws an error if the requested method does not exist', async () => {
const { request, close } = await installSnap();
const response = await request({
method: 'foo',
});
expect(response).toRespondWithError({
code: -32603,
message: 'Internal JSON-RPC error.',
data: {
cause: {
message: 'The method does not exist / is not available.',
stack: expect.any(String),
},
},
});
await close();
});
describe('inApp', () => {
it('sends an in-app notification', async () => {
const { request, close } = await installSnap();
const response = await request({
method: 'inApp',
origin: 'Jest',
});
expect(response).toRespondWith(null);
expect(response).toSendNotification(
'Hello from within MetaMask!',
NotificationType.InApp,
);
await close();
});
});
describe('native', () => {
it('sends a native notification', async () => {
const { request, close } = await installSnap();
const response = await request({
method: 'native',
origin: 'Jest',
});
expect(response).toRespondWith(null);
expect(response).toSendNotification(
'Hello, Jest, from the browser!',
NotificationType.Native,
);
await close();
});
});
});