Skip to content

Commit 7abe081

Browse files
committed
test: add unit test for GraphQLStatementsFormatter class
1 parent 3fd05f5 commit 7abe081

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { GraphQLStatementsFormatter } = require('../../src/utils');
2+
3+
describe('GraphQL statements Formatter', () => {
4+
const statements = new Map();
5+
statements.set('getTodo', `
6+
query GetProject($id: ID!) {
7+
getProject(id: $id) {
8+
id
9+
name
10+
createdAt
11+
updatedAt
12+
}
13+
}
14+
`);
15+
16+
it('Generates formatted output for JS frontend', () => {
17+
const formattedOutput = (new GraphQLStatementsFormatter('javascript')).format(statements);
18+
expect(formattedOutput).toMatchSnapshot();
19+
});
20+
21+
it('Generates formatted output for TS frontend', () => {
22+
const formattedOutput = (new GraphQLStatementsFormatter('typescript')).format(statements);
23+
expect(formattedOutput).toMatchSnapshot();
24+
});
25+
26+
it('Generates formatted output for Flow frontend', () => {
27+
const formattedOutput = (new GraphQLStatementsFormatter('flow')).format(statements);
28+
expect(formattedOutput).toMatchSnapshot();
29+
});
30+
31+
it('Generates formatted output for Angular frontend', () => {
32+
const formattedOutput = (new GraphQLStatementsFormatter('angular')).format(statements);
33+
// Note that for Angular, we generate in GraphQL language itself.
34+
expect(formattedOutput).toMatchSnapshot();
35+
});
36+
37+
it('Generates formatted output for GraphQL language', () => {
38+
const formattedOutput = (new GraphQLStatementsFormatter('graphql')).format(statements);
39+
expect(formattedOutput).toMatchSnapshot();
40+
});
41+
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`GraphQL statements Formatter Generates formatted output for Angular frontend 1`] = `
4+
"# this is an auto generated file. This will be overwritten
5+
6+
query GetProject($id: ID!) {
7+
getProject(id: $id) {
8+
id
9+
name
10+
createdAt
11+
updatedAt
12+
}
13+
}
14+
"
15+
`;
16+
17+
exports[`GraphQL statements Formatter Generates formatted output for Flow frontend 1`] = `
18+
"// @flow
19+
// this is an auto generated file. This will be overwritten
20+
21+
export const getTodo = /* GraphQL */ \`
22+
query GetProject($id: ID!) {
23+
getProject(id: $id) {
24+
id
25+
name
26+
createdAt
27+
updatedAt
28+
}
29+
}
30+
\`;
31+
"
32+
`;
33+
34+
exports[`GraphQL statements Formatter Generates formatted output for GraphQL language 1`] = `
35+
"# this is an auto generated file. This will be overwritten
36+
37+
query GetProject($id: ID!) {
38+
getProject(id: $id) {
39+
id
40+
name
41+
createdAt
42+
updatedAt
43+
}
44+
}
45+
"
46+
`;
47+
48+
exports[`GraphQL statements Formatter Generates formatted output for JS frontend 1`] = `
49+
"/* eslint-disable */
50+
// this is an auto generated file. This will be overwritten
51+
52+
export const getTodo = /* GraphQL */ \`
53+
query GetProject($id: ID!) {
54+
getProject(id: $id) {
55+
id
56+
name
57+
createdAt
58+
updatedAt
59+
}
60+
}
61+
\`;
62+
"
63+
`;
64+
65+
exports[`GraphQL statements Formatter Generates formatted output for TS frontend 1`] = `
66+
"/* tslint:disable */
67+
/* eslint-disable */
68+
// this is an auto generated file. This will be overwritten
69+
70+
export const getTodo = /* GraphQL */ \`
71+
query GetProject($id: ID!) {
72+
getProject(id: $id) {
73+
id
74+
name
75+
createdAt
76+
updatedAt
77+
}
78+
}
79+
\`;
80+
"
81+
`;

0 commit comments

Comments
 (0)