Skip to content

Commit

Permalink
Eliminate console error when running test (#1179)
Browse files Browse the repository at this point in the history
* Eliminate console error when running test

The network client test "queues requests while a previous identical
call is still pending..." was emitting a console error due to an
unmocked block tracker network call.

That call is now mocked, eliminating the error.

I am unsure why the second call is made during this test, but we
suspect that it's because the first block tracker call isn't being
cached until after the RPC call that triggered it has been resolved.

To reproduce, use `.only` on that test and run this command:

`yarn workspace @metamask/network-controller jest --coverage=false --verbose=false`

Before this change, that command should produce console errors. After
this change, there will be none (though there are still lots of
warnings).

This relates to #1178

* Eliminate error in second test
  • Loading branch information
Gudahtt authored and MajorLift committed Oct 11, 2023
1 parent c07d1dd commit 15a4a44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ export const testsForRpcMethodSupportingBlockParam = (
// block-cache middleware will request the latest block number
// through the block tracker to determine the cache key.
comms.mockNextBlockTrackerRequest();
// A second block tracker request is made for some reason
comms.mockNextBlockTrackerRequest();
comms.mockRpcCall({
delay: 100,
request: buildRequestWithReplacedBlockParam(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const testsForRpcMethodAssumingNoBlockParam = (
});

for (const paramIndex of [...Array(numberOfParameters).keys()]) {
it(`does not reuse the result of a previous request if parameter at index "${paramIndex}" differs`, async () => {// eslint-disable-line
it(`does not reuse the result of a previous request if parameter at index "${paramIndex}" differs`, async () => {
const firstMockParams = [
...new Array(numberOfParameters).fill('some value'),
];
Expand Down Expand Up @@ -215,6 +215,8 @@ export const testsForRpcMethodAssumingNoBlockParam = (
// number is retrieved through the block tracker first. It doesn't
// matter what this is — it's just used as a cache key.
comms.mockNextBlockTrackerRequest();
// A second block tracker request is made for some reason
comms.mockNextBlockTrackerRequest();
comms.mockRpcCall({
request: requests[0],
response: { result: mockResults[0] },
Expand Down

0 comments on commit 15a4a44

Please sign in to comment.