Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix Jest polyfills #144

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-starfishes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/graphql-testing-library": patch
---

Use 50ms as the delay value in Node processes, since 20ms was still resulting in occasional batched renders.
2 changes: 1 addition & 1 deletion .storybook/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.3.5'
const PACKAGE_VERSION = '2.4.9'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
4 changes: 2 additions & 2 deletions jest.polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Object.defineProperties(globalThis, {
File: { value: File },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request },
Response: { value: Response },
Request: { value: Request, configurable: true },
Response: { value: Response, configurable: true },
});

// Symbol.dispose is not defined
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/handlers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,6 @@ describe("unit tests", () => {

// @ts-expect-error intentionally accessing a property that has been
// excluded from the type
expect(ecommerceHandler.replaceDelay["currentDelay"]).toBe(20);
expect(ecommerceHandler.replaceDelay["currentDelay"]).toBe(50);
});
});
2 changes: 1 addition & 1 deletion src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function createHandlerFromSchema<TResolvers>(
// This sometimes caused multipart responses to be batched into a single
// render by React, so we'll use a longer delay of 20ms.
if (_delay === "real" && isNodeProcess()) {
_delay = 20;
_delay = 50;
}

let testSchema: GraphQLSchema = schema;
Expand Down
6 changes: 5 additions & 1 deletion src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ function createDefaultResolvers(typesMap: Map<string, Set<string>>) {
for (const key of typesMap.keys()) {
defaultResolvers[key] = {
__resolveType(data) {
return data.__typename || typesMap.get(key)?.values().next().value;
return (
// fallback to an empty string here to satisfy TS, since
// all keys in typesMap should have '
data.__typename || typesMap.get(key)?.values().next().value || ""
);
},
};
}
Expand Down
Loading