forked from apollographql/apollo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApolloServer.test.ts
40 lines (35 loc) 路 979 Bytes
/
ApolloServer.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import MockReq = require('mock-req');
import { ApolloServerBase } from '../ApolloServer';
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';
const queryType = new GraphQLObjectType({
name: 'QueryType',
fields: {
testString: {
type: GraphQLString,
resolve() {
return 'it works';
},
},
},
});
describe('ApolloServer', () => {
describe('executeOperation', () => {
it('Passes the request object to the context callback', () => {
const schema = new GraphQLSchema({
query: queryType,
});
const contextMock = jest.fn();
const apolloServer = new ApolloServerBase({
schema,
context: contextMock,
});
const mockRequest = new MockReq();
const operation = {
query: '{ }',
http: mockRequest,
};
apolloServer.executeOperation(operation);
expect(contextMock).toHaveBeenCalledWith({ req: operation });
});
});
});