-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathmock.test.ts
More file actions
57 lines (50 loc) · 1.31 KB
/
mock.test.ts
File metadata and controls
57 lines (50 loc) · 1.31 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import { createMockMiddleware } from './mock';
import { createStore } from '../store';
import { addJsonRpcMock } from '../store/mocks';
import { getMockOptions } from '../test-utils';
describe('createMockMiddleware', () => {
it('mocks a JSON-RPC method', async () => {
const { store } = createStore(getMockOptions());
store.dispatch(
addJsonRpcMock({
id: 'foo',
implementation: () => 'bar',
once: false,
}),
);
const engine = new JsonRpcEngine();
engine.push(createMockMiddleware(store));
expect(
await engine.handle({
jsonrpc: '2.0',
id: 1,
method: 'foo',
}),
).toStrictEqual({
jsonrpc: '2.0',
id: 1,
result: 'bar',
});
});
it('calls the next middleware if no mock is found', async () => {
const { store } = createStore(getMockOptions());
const engine = new JsonRpcEngine();
engine.push(createMockMiddleware(store));
engine.push((_request, response, _next, end) => {
response.result = 'next';
end();
});
expect(
await engine.handle({
jsonrpc: '2.0',
id: 1,
method: 'foo',
}),
).toStrictEqual({
jsonrpc: '2.0',
id: 1,
result: 'next',
});
});
});