From 15a4a444dcde35af2a4fc30e94e0b101a57c7f58 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 14 Apr 2023 14:09:51 -0230 Subject: [PATCH] Eliminate console error when running test (#1179) * 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 --- .../tests/provider-api-tests/block-param.ts | 2 ++ .../tests/provider-api-tests/no-block-param.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/network-controller/tests/provider-api-tests/block-param.ts b/packages/network-controller/tests/provider-api-tests/block-param.ts index 982150bfdcd..4cc939db1f3 100644 --- a/packages/network-controller/tests/provider-api-tests/block-param.ts +++ b/packages/network-controller/tests/provider-api-tests/block-param.ts @@ -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( diff --git a/packages/network-controller/tests/provider-api-tests/no-block-param.ts b/packages/network-controller/tests/provider-api-tests/no-block-param.ts index 018b8c8e017..92e2782e9e2 100644 --- a/packages/network-controller/tests/provider-api-tests/no-block-param.ts +++ b/packages/network-controller/tests/provider-api-tests/no-block-param.ts @@ -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'), ]; @@ -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] },