Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: support TypedDocumentString as query argument #609

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Changes from 1 commit
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
Prev Previous commit
Align tests with new mock style
  • Loading branch information
fpapado committed Jan 7, 2025
commit 77edf5ed696af27855ef0f6e0d9c279ccadc66f2
54 changes: 28 additions & 26 deletions 54 test/graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ describe("graphql()", () => {
},
};

const mock = fetchMock.createInstance().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
accept: "application/vnd.github.v3+json",
authorization: "token secret123",
"user-agent": userAgent,
},
},
);

const RepositoryDocument = new TypedDocumentString<
{
repository: { issues: { edges: Array<{ node: { title: string } }> } };
Expand All @@ -142,17 +154,7 @@ describe("graphql()", () => {
authorization: `token secret123`,
},
request: {
fetch: fetchMock.sandbox().post(
"https://api.github.com/graphql",
{ data: mockData },
{
headers: {
accept: "application/vnd.github.v3+json",
authorization: "token secret123",
"user-agent": userAgent,
},
},
),
fetch: mock.fetchHandler,
},
}).then((result) => {
expect(JSON.stringify(result)).toStrictEqual(JSON.stringify(mockData));
Expand Down Expand Up @@ -220,28 +222,28 @@ describe("graphql()", () => {
}
}`);

const mock = fetchMock
.createInstance()
.post("https://api.github.com/graphql", (callHistory) => {
//@ts-ignore mock.fetchHandler is not typed
const body = JSON.parse(mock.callHistory.calls()[0].options.body);
expect(body.query).toEqual(query.toString());
expect(body.variables).toStrictEqual({
owner: "octokit",
repo: "graphql.js",
});

return { data: {} };
});

return graphql(query, {
headers: {
authorization: `token secret123`,
},
owner: "octokit",
repo: "graphql.js",
request: {
fetch: fetchMock
.sandbox()
.post(
"https://api.github.com/graphql",
(_url, options: OctokitTypes.RequestOptions) => {
const body = JSON.parse(options.body);
expect(body.query).toEqual(query.toString());
expect(body.variables).toStrictEqual({
owner: "octokit",
repo: "graphql.js",
});

return { data: {} };
},
),
fetch: mock.fetchHandler,
},
});
});
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.