Skip to content

Commit 3beb355

Browse files
committed
Add test coverage for schema validation options.
1 parent bb9c68c commit 3beb355

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/type/__tests__/schema-test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,66 @@ describe('Type System: Schema', () => {
9595
expect(Schema.getTypeMap()).to.include.key('WrappedDirInput');
9696
});
9797
});
98+
99+
describe('Validity', () => {
100+
describe('when not assumed valid', () => {
101+
it('configures the schema to still needing validation', () => {
102+
expect(
103+
new GraphQLSchema({
104+
assumeValid: false,
105+
}).__validationErrors,
106+
).to.equal(undefined);
107+
});
108+
109+
it('configures the schema for allowed legacy names', () => {
110+
expect(
111+
new GraphQLSchema({
112+
allowedLegacyNames: ['__badName'],
113+
}).__allowedLegacyNames,
114+
).to.deep.equal(['__badName']);
115+
});
116+
117+
it('checks the configuration for mistakes', () => {
118+
expect(() => new GraphQLSchema(() => null)).to.throw();
119+
expect(() => new GraphQLSchema({ types: {} })).to.throw();
120+
expect(() => new GraphQLSchema({ directives: {} })).to.throw();
121+
expect(() => new GraphQLSchema({ allowedLegacyNames: {} })).to.throw();
122+
});
123+
});
124+
125+
describe('when assumed valid', () => {
126+
it('configures the schema to have no errors', () => {
127+
expect(
128+
new GraphQLSchema({
129+
assumeValid: true,
130+
}).__validationErrors,
131+
).to.deep.equal([]);
132+
});
133+
134+
it('still configures the schema for allowed legacy names', () => {
135+
expect(
136+
new GraphQLSchema({
137+
assumeValid: true,
138+
allowedLegacyNames: ['__badName'],
139+
}).__allowedLegacyNames,
140+
).to.deep.equal(['__badName']);
141+
});
142+
143+
it('does not check the configuration for mistakes', () => {
144+
expect(() => {
145+
const config = () => null;
146+
config.assumeValid = true;
147+
return new GraphQLSchema(config);
148+
}).to.not.throw();
149+
expect(() => {
150+
return new GraphQLSchema({
151+
assumeValid: true,
152+
types: {},
153+
directives: { reduce: () => [] },
154+
allowedLegacyNames: {},
155+
});
156+
}).to.not.throw();
157+
});
158+
});
159+
});
98160
});

0 commit comments

Comments
 (0)