Skip to content

Commit

Permalink
add failing test for missing object prototype (ardatan#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
patotoma committed Sep 7, 2016
1 parent 4edf4a1 commit d859eb9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/testMocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,50 @@ describe('Mock', () => {
});
});

it('inherits object prototype for objects', () => {
const short = `
type Thread {
id: ID!
name: String!
}
type RootQuery {
thread(id: ID): Thread
}
schema {
query: RootQuery
}
`;
const jsSchema = buildSchemaFromTypeDefinitions(short);
const mockMap = {
RootQuery: () => ({
thread: (o, a) => ({ id: a.id }),
}),
Thread: () => ({
name: 'Lorem Ipsum',
}),
};
addMockFunctionsToSchema({ schema: jsSchema, mocks: mockMap });
const testQuery = `query abc{
thread(id: "67"){
id
name
}
}`;
const expected = {
thread: {
id: '67',
name: 'Lorem Ipsum',
},
};
return graphql(jsSchema, testQuery).then((res) => {
expect(Object.getPrototypeOf(res.data.thread)).to.deep.equal(
Object.getPrototypeOf(expected)
);
});
});

// TODO add a test that checks that even when merging defaults, lists invoke
// the function for every object, not just once per list.

Expand Down

0 comments on commit d859eb9

Please sign in to comment.