Skip to content

Instantly share code, notes, and snippets.

@PCreations
Created September 3, 2020 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PCreations/e03a83ce131df41bf254ca8417e40ba0 to your computer and use it in GitHub Desktop.
Save PCreations/e03a83ce131df41bf254ca8417e40ba0 to your computer and use it in GitHub Desktop.
import { createTestServer } from "./test-server";
import {
executeLatestArticlesQuery,
GraphQLError,
} from "../execute-latest-articles-query";
import { createTestArticlePublishedOneDayAgo } from "./data/create-test-article";
describe("executeLatestArticlesQuery", () => {
let testServer;
beforeAll((done) => {
testServer = createTestServer({ port: 4123 });
testServer.listen(done);
});
afterAll((done) => {
testServer.close(done);
});
it("executes the correct request", async () => {
[...]
});
it("get the latest articles from the graphQL response", async () => {
[...]
});
it("fails with a GraphQLError if there are graphQL errors in the response", async () => {
// arrange
expect.assertions(1);
const domain = "www.my-website.co.uk";
const graphQLEndpoint = "http://localhost:4123";
const expectedErrors = [
{
message: "some error",
},
{
message: "some other error",
},
];
testServer.setResponse({
status: 400,
body: {
errors: expectedErrors,
},
});
// act & assert
await expect(
executeLatestArticlesQuery({ domain, graphQLEndpoint })
).rejects.toEqual(new GraphQLError(expectedErrors));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment