Skip to content

Commit

Permalink
test(rpc): customized fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Nov 27, 2023
1 parent b04bf4b commit 6380e04
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/rpc/__tests__/custom-fetch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { RPC } = require("..");

describe("custom fetch", () => {
test("should work", async () => {
const customizedFetch = jest.fn((_, { body }) =>
Promise.resolve({
json: () =>
Promise.resolve({
jsonrpc: "2.0",
result: "0x8dd",
id: JSON.parse(body).id,
}),
})
);

const rpc = new RPC("", { fetch: customizedFetch });
await rpc.getTipBlockNumber();

expect(customizedFetch).toBeCalled();
expect(JSON.parse(customizedFetch.mock.calls[0][1].body)).toHaveProperty(
"method",
"get_tip_block_number"
);
});
});

0 comments on commit 6380e04

Please sign in to comment.