From 43bdf578884c002d1271f47ca963f200bd8f31f7 Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sun, 21 Feb 2021 21:18:01 -0600 Subject: [PATCH] internal(fix): Update fetch polyfill for tests and fix some tests --- package.json | 4 ++-- .../__tests__/integration-endpoint.web.tsx | 2 +- packages/endpoint/src/__tests__/endpoint.ts | 4 ++-- packages/hooks/src/__tests__/useCancelling.ts | 6 +++++- yarn.lock | 9 +++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c44b04f5049..00b87749cf3 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "jest": "^26.6.3", "lerna": "^4.0.0", "mkdirp": "^1.0.4", - "nock": "^13.0.6", + "nock": "^13.1.0", "prettier": "^2.2.1", "react": "^18.0.0-0", "react-dom": "^18.0.0-0", @@ -81,7 +81,7 @@ "ts-node": "^9.1.1", "ttypescript": "^1.5.12", "typescript": "^4.1.3", - "whatwg-fetch": "3.0.0" + "whatwg-fetch": "3.6.2" }, "resolutions": { "@lerna/conventional-commits": "https://github.com/ntucker/lerna-conventional-commits.git" diff --git a/packages/core/src/react-integration/__tests__/integration-endpoint.web.tsx b/packages/core/src/react-integration/__tests__/integration-endpoint.web.tsx index 243544663f8..fbf13ebf3bc 100644 --- a/packages/core/src/react-integration/__tests__/integration-endpoint.web.tsx +++ b/packages/core/src/react-integration/__tests__/integration-endpoint.web.tsx @@ -810,7 +810,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) { }), ); - // second optimistic + // third optimistic mynock .patch('/article-cooler/5') .delay(500) diff --git a/packages/endpoint/src/__tests__/endpoint.ts b/packages/endpoint/src/__tests__/endpoint.ts index 426171c4061..0b65599db2e 100644 --- a/packages/endpoint/src/__tests__/endpoint.ts +++ b/packages/endpoint/src/__tests__/endpoint.ts @@ -586,10 +586,10 @@ describe('Endpoint', () => { expect(user.username).toBe(payload.username); }); - it('should reject when aborted', () => { + it('should reject when aborted', async () => { const abort = new AbortController(); const AbortUser = UserDetail.extend({ signal: abort.signal }); - expect(async () => { + await expect(async () => { const promise = AbortUser({ id: payload.id }); abort.abort(); return await promise; diff --git a/packages/hooks/src/__tests__/useCancelling.ts b/packages/hooks/src/__tests__/useCancelling.ts index bf3d6d166a6..9046d5b4b38 100644 --- a/packages/hooks/src/__tests__/useCancelling.ts +++ b/packages/hooks/src/__tests__/useCancelling.ts @@ -34,6 +34,10 @@ describe('useCancelling()', () => { .delay(2000) .reply(200, payload2); }); + afterAll(() => { + jest.useRealTimers(); + nock.cleanAll(); + }); it('should abort when props change and resolve when kept the same', async () => { const { result, rerender } = renderHook( @@ -50,7 +54,7 @@ describe('useCancelling()', () => { expect(ogPromise).rejects.toMatchInlineSnapshot(`[AbortError: Aborted]`); const nextPromise = result.current({ id: '7' }); jest.advanceTimersByTime(2000); - await expect(nextPromise).resolves.toMatchInlineSnapshot(` + expect(nextPromise).resolves.toMatchInlineSnapshot(` Object { "id": "7", "title": "second one", diff --git a/yarn.lock b/yarn.lock index aa5e986ddd2..aa6931df501 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8680,7 +8680,7 @@ nocache@^2.1.0: resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.1.0.tgz#120c9ffec43b5729b1d5de88cd71aa75a0ba491f" integrity sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q== -nock@^13.0.6: +nock@^13.1.0: version "13.1.0" resolved "https://registry.yarnpkg.com/nock/-/nock-13.1.0.tgz#41c8ce8b35ab7d618c4cbf40de1d5bce319979ba" integrity sha512-3N3DUY8XYrxxzWazQ+nSBpiaJ3q6gcpNh4gXovC/QBxrsvNp4tq+wsLHF6mJ3nrn3lPLn7KCJqKxy/9aD+0fdw== @@ -11996,7 +11996,12 @@ whatwg-encoding@^1.0.5: dependencies: iconv-lite "0.4.24" -whatwg-fetch@3.0.0, whatwg-fetch@^3.0.0: +whatwg-fetch@3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c" + integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA== + +whatwg-fetch@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb" integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==