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

Remove itAsync from remaining relevant tests #12210

Open
wants to merge 44 commits into
base: jerel/remove-itasync-part-2
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
25617fe
Remove itAsync from useMutation tests
jerelmiller Nov 30, 2024
c9d5467
Remove itAsync from useReactiveVar tests
jerelmiller Nov 30, 2024
1e08c42
Remove itAsync from HttpLink tests
jerelmiller Nov 30, 2024
ea73797
Remove itAsync from ApolloConsumer tests
jerelmiller Nov 30, 2024
4802fd0
Remove itAsync from webSocketLink tests
jerelmiller Nov 30, 2024
e66e7a1
Add ability to unsubscribe from observable in ObservableStream
jerelmiller Dec 2, 2024
091c7fd
Remove itAsync from persisted-queries tests
jerelmiller Dec 2, 2024
a4127bf
Remove itAsync from fragmentMatcher tests
jerelmiller Dec 2, 2024
2a16313
Remove itAsync from link/error tests
jerelmiller Dec 2, 2024
cdadb6f
Remove itAsync from client tests
jerelmiller Dec 5, 2024
b8242b4
Remove itAsync from writeToStore tests
jerelmiller Dec 5, 2024
fa83b8e
Allow toEmitError to compare error string
jerelmiller Dec 5, 2024
6eb840b
Remove itAsync from link/context tests
jerelmiller Dec 5, 2024
45792a2
Remove itAsync from ApolloClient tests
jerelmiller Dec 6, 2024
243d775
Remove itAsync from getDataFromTree tests
jerelmiller Dec 6, 2024
8fdd503
Remove itAsync from batchHttpLink tests
jerelmiller Dec 6, 2024
5b1f7a5
Remove itAsync from batchLink tests
jerelmiller Dec 7, 2024
4e642d6
Remove itAsync from fetchPolicies tests
jerelmiller Dec 7, 2024
3f66241
Remove itAsync from asyncMap tests
jerelmiller Dec 7, 2024
305a7e0
Remove itAsync from QueryManager/links tests
jerelmiller Dec 7, 2024
41b0905
Remove itAsync from local-state/resolvers tests
jerelmiller Dec 7, 2024
9e6efd1
Rename assertWithObserver to setupTestWithResolvers
jerelmiller Dec 7, 2024
5feb605
Remove itAsync from local-state/general tests
jerelmiller Dec 7, 2024
701d1a0
Use expect(...).rejects to check for errors
jerelmiller Dec 9, 2024
5019939
Ensure promise is awaited on assertion
jerelmiller Dec 9, 2024
e9d84ba
Default to false for boolean
jerelmiller Dec 9, 2024
81614e5
Remove itAsync from QueryManager/recycler tests
jerelmiller Dec 9, 2024
c40d468
Remove itAsync from local-state/export tests
jerelmiller Dec 9, 2024
8c83909
Silence cache write warnings in local-state/export tests
jerelmiller Dec 9, 2024
1102701
Remove itAsync from MockedProvider tests
jerelmiller Dec 9, 2024
1ac25c7
Remove itAsync from subscribeToMore tests
jerelmiller Dec 10, 2024
615ccfb
Remove itAsync from QueryManager/multiple-results tests
jerelmiller Dec 10, 2024
3035297
Remove itAsync from ApolloLink tests
jerelmiller Dec 10, 2024
9e36b6f
Remove itAsync from QueryManager/index tests
jerelmiller Dec 10, 2024
e0827a6
Stop using observableToPromise in QueryManager/index tests
jerelmiller Dec 11, 2024
fc7ca7f
Remove unused observableToPromise testing utility
jerelmiller Dec 11, 2024
b30bbbd
Remove itAsync from local-state/subscriptions tests
jerelmiller Dec 11, 2024
1775e15
Remove itAsync from parseAndCheckHttpResponse tests
jerelmiller Dec 11, 2024
c976713
Remove itAsync from optimistic tests
jerelmiller Dec 11, 2024
1a3bab7
Remove itAsync from refetchQueries tests
jerelmiller Dec 12, 2024
bf90069
Remove itAsync from Concast tests
jerelmiller Dec 12, 2024
67b57f0
Remove itAsync from toPromise tests
jerelmiller Dec 12, 2024
18ff5c0
Remove itAsync from graphqlSubscriptions tests
jerelmiller Dec 12, 2024
1e7d108
Remove itAsync from schemaLink tests
jerelmiller Dec 12, 2024
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
Prev Previous commit
Remove itAsync from schemaLink tests
jerelmiller committed Dec 12, 2024
commit 1e7d1085aa105a4350fb8f06b180930c8fccf573
184 changes: 68 additions & 116 deletions src/link/schema/__tests__/schemaLink.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import gql from "graphql-tag";

import { execute } from "../../core/execute";
import { SchemaLink } from "../";
import { itAsync } from "../../../testing";
import { ObservableStream } from "../../../testing/internal";

const sampleQuery = gql`
query SampleQuery {
@@ -51,25 +51,18 @@ describe("SchemaLink", () => {
expect(link.schema).toEqual(schema);
});

itAsync("calls next and then complete", (resolve, reject) => {
const next = jest.fn();
it("calls next and then complete", async () => {
const link = new SchemaLink({ schema });
const observable = execute(link, {
query: sampleQuery,
});
observable.subscribe({
next,
error: () => {
throw new Error("Received error");
},
complete: () => {
expect(next).toHaveBeenCalledTimes(1);
resolve();
},
});
const stream = new ObservableStream(observable);

await expect(stream).toEmitNext();
await expect(stream).toComplete();
});

itAsync("calls error when fetch fails", (resolve, reject) => {
it("calls error when fetch fails", async () => {
const link = new SchemaLink({
validate: true,
schema: makeExecutableSchema({
@@ -86,98 +79,67 @@ describe("SchemaLink", () => {
const observable = execute(link, {
query: sampleQuery,
});
observable.subscribe((result) => {
expect(result.errors).toBeTruthy();
expect(result.errors!.length).toBe(1);
expect(result.errors![0].message).toMatch(/Unauthorized/);
resolve();
const stream = new ObservableStream(observable);

await expect(stream).toEmitValue({
data: { sampleQuery: null },
errors: [{ message: "Unauthorized", path: ["sampleQuery"] }],
});
});

itAsync(
"supports query which is executed synchronously",
(resolve, reject) => {
const next = jest.fn();
const link = new SchemaLink({ schema });
const introspectionQuery = gql`
query IntrospectionQuery {
__schema {
types {
name
}
it("supports query which is executed synchronously", async () => {
const link = new SchemaLink({ schema });
const introspectionQuery = gql`
query IntrospectionQuery {
__schema {
types {
name
}
}
`;
const observable = execute(link, {
query: introspectionQuery,
});
observable.subscribe(
next,
() => {
throw new Error("Received error");
},
() => {
expect(next).toHaveBeenCalledTimes(1);
resolve();
}
);
}
);

itAsync(
"passes operation context into execute with context function",
(resolve, reject) => {
const next = jest.fn();
const contextValue = { some: "value" };
const contextProvider = jest.fn((operation) => operation.getContext());
const resolvers = {
Query: {
sampleQuery: (root: any, args: any, context: any) => {
try {
expect(context).toEqual(contextValue);
} catch (error) {
reject("Should pass context into resolver");
}
},
}
`;
const observable = execute(link, {
query: introspectionQuery,
});
const stream = new ObservableStream(observable);

await expect(stream).toEmitNext();
await expect(stream).toComplete();
});

it("passes operation context into execute with context function", async () => {
const contextValue = { some: "value" };
const contextProvider = jest.fn((operation) => operation.getContext());
const resolvers = {
Query: {
sampleQuery: (root: any, args: any, context: any) => {
expect(context).toEqual(contextValue);
},
};
const schemaWithResolvers = makeExecutableSchema({
typeDefs,
resolvers,
});
const link = new SchemaLink({
schema: schemaWithResolvers,
context: contextProvider,
});
const observable = execute(link, {
query: sampleQuery,
context: contextValue,
});
observable.subscribe(
next,
(error) => reject("Shouldn't call onError"),
() => {
try {
expect(next).toHaveBeenCalledTimes(1);
expect(contextProvider).toHaveBeenCalledTimes(1);
resolve();
} catch (e) {
reject(e);
}
}
);
}
);
},
};
const schemaWithResolvers = makeExecutableSchema({
typeDefs,
resolvers,
});
const link = new SchemaLink({
schema: schemaWithResolvers,
context: contextProvider,
});
const observable = execute(link, {
query: sampleQuery,
context: contextValue,
});
const stream = new ObservableStream(observable);

await expect(stream).toEmitNext();
await expect(stream).toComplete();
expect(contextProvider).toHaveBeenCalledTimes(1);
});

itAsync("passes static context into execute", (resolve, reject) => {
const next = jest.fn();
it("passes static context into execute", async () => {
const contextValue = { some: "value" };
const resolver = jest.fn((root, args, context) => {
try {
expect(context).toEqual(contextValue);
} catch (error) {
reject("Should pass context into resolver");
}
expect(context).toEqual(contextValue);
});

const resolvers = {
@@ -196,22 +158,14 @@ describe("SchemaLink", () => {
const observable = execute(link, {
query: sampleQuery,
});
observable.subscribe(
next,
(error) => reject("Shouldn't call onError"),
() => {
try {
expect(next).toHaveBeenCalledTimes(1);
expect(resolver).toHaveBeenCalledTimes(1);
resolve();
} catch (e) {
reject(e);
}
}
);
const stream = new ObservableStream(observable);

await expect(stream).toEmitNext();
await expect(stream).toComplete();
expect(resolver).toHaveBeenCalledTimes(1);
});

itAsync("reports errors for unknown queries", (resolve, reject) => {
it("reports errors for unknown queries", async () => {
const link = new SchemaLink({
validate: true,
schema: makeExecutableSchema({
@@ -225,11 +179,9 @@ describe("SchemaLink", () => {
}
`,
});
observable.subscribe((result) => {
expect(result.errors).toBeTruthy();
expect(result.errors!.length).toBe(1);
expect(result.errors![0].message).toMatch(/Cannot query field "unknown"/);
resolve();
const stream = new ObservableStream(observable);
await expect(stream).toEmitValue({
errors: [{ message: 'Cannot query field "unknown" on type "Query".' }],
});
});
});