Skip to content

Commit

Permalink
tests: fix jest/coveralls syntax, unmock toApolloError
Browse files Browse the repository at this point in the history
- jest/coveralls recently patched their suggested usage due to tests failing but being passed by how coveralls is used
- unmocked toApolloError to enforce correct usage
  • Loading branch information
the-vampiire committed May 1, 2020
1 parent 91fd16c commit 69a0107
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
20 changes: 6 additions & 14 deletions lib/utils/tests/create-apollo-error.util.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const { toApolloError } = require("apollo-server-core");
const { defaultFallback } = require("../../core/constants");
const createApolloError = require("../create-apollo-error");

jest.mock("apollo-server-core", () => ({
toApolloError: jest.fn(arg => arg),
}));

const path = ["a", "path"];
const locations = [{ line: 1, column: 1 }];
const originalError = {
Expand All @@ -31,25 +26,22 @@ describe("createApolloError: converts the original error to an Apollo Error", ()
result = createApolloError(graphQLError, mapItem);
});

test("converts the error to an Apollo Error", () => {
expect(toApolloError).toHaveBeenCalled();
});

test("converted error includes the GraphQL path and location", () => {
["path", "location"].forEach(property => expect(result[property]).toBe(graphQLError[property]));
["path", "location"].forEach(property =>
expect(result[property]).toBe(graphQLError[property]),
);
});

test("converted error has a top level message property from the mapItem", () => expect(result.message).toBe(mapItem.message));
test("converted error has a top level message property from the mapItem", () =>
expect(result.message).toBe(mapItem.message));

test("converted error includes extensions object, { code, data }, from the mapItem", () => {
expect(result.extensions).toBeDefined();
expect(result.extensions.data).toBe(mapItem.data);
expect(result.extensions.code).toBe(mapItem.code);
});

test(`mapItem.code is not provided: uses default fallback code [${
defaultFallback.code
}]`, () => {
test(`mapItem.code is not provided: uses default fallback code [${defaultFallback.code}]`, () => {
const noCodeResult = createApolloError(graphQLError, {
message: "no code",
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "jest",
"test:core": "jest */*.core.test*",
"test:utils": "jest */*.util.test*",
"test:travis": "jest --no-cache --coverage --coverageReporters=text-lcov | coveralls"
"test:travis": "jest --no-cache --coverage && coveralls < coverage/lcov.info"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 69a0107

Please sign in to comment.