Created
September 3, 2020 11:40
-
-
Save PCreations/e03a83ce131df41bf254ca8417e40ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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