Skip to content

Commit

Permalink
Test mocking a resolver field
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Nov 8, 2022
1 parent 3b7a49a commit ef03921
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const typeDefs = `
type Query {
posts: [Post]
author(id: ID!): Author
randomInt(seed: Int): Int
}
type Mutation {
Expand Down Expand Up @@ -395,6 +396,31 @@ describe("graphql-fakester", () => {
});
});

describe("mocking a resolver on an object", () => {
beforeEach(() => {
mock = new GraphQLMock({
typeDefs,
mocks: {
Query: {
randomInt: 0,
},
},
});
});

const randomIntQuery = `
query randomIntQuery {
randomInt
}
`;

it("uses the provided result will be used", async () => {
const result = await mock.execute(randomIntQuery);

expect(result, "to inspect as snapshot", "{ data: { randomInt: 0 } }");
});
});

describe("when hardcoding a field on an object", () => {
beforeEach(async () => {
mock = new GraphQLMock({
Expand Down

0 comments on commit ef03921

Please sign in to comment.