Skip to content

Commit fdf981c

Browse files
committed
Switch Enum tests to not depend on JSON representation
If we add additional fields (e.g. astNode) into values of enum these test will be broken.
1 parent f2d2d24 commit fdf981c

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

src/utilities/__tests__/buildASTSchema-test.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -540,29 +540,18 @@ describe('Schema Builder', () => {
540540
const ast = parse(body);
541541
const schema = buildASTSchema(ast);
542542

543-
expect(schema.getType('MyEnum').getValues()).to.deep.equal([
544-
{
545-
name: 'VALUE',
546-
description: '',
547-
isDeprecated: false,
548-
deprecationReason: undefined,
549-
value: 'VALUE'
550-
},
551-
{
552-
name: 'OLD_VALUE',
553-
description: '',
554-
isDeprecated: true,
555-
deprecationReason: 'No longer supported',
556-
value: 'OLD_VALUE'
557-
},
558-
{
559-
name: 'OTHER_VALUE',
560-
description: '',
561-
isDeprecated: true,
562-
deprecationReason: 'Terrible reasons',
563-
value: 'OTHER_VALUE'
564-
}
565-
]);
543+
const myEnum = schema.getType('MyEnum');
544+
545+
const value = myEnum.getValue('VALUE');
546+
expect(value.isDeprecated).to.equal(false);
547+
548+
const oldValue = myEnum.getValue('OLD_VALUE');
549+
expect(oldValue.isDeprecated).to.equal(true);
550+
expect(oldValue.deprecationReason).to.equal('No longer supported');
551+
552+
const otherValue = myEnum.getValue('OTHER_VALUE');
553+
expect(otherValue.isDeprecated).to.equal(true);
554+
expect(otherValue.deprecationReason).to.equal('Terrible reasons');
566555

567556
const rootFields = schema.getType('Query').getFields();
568557
expect(rootFields.field1.isDeprecated).to.equal(true);

src/utilities/__tests__/extendSchema-test.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,10 @@ describe('extendSchema', () => {
215215
expect(deprecatedFieldDef.deprecationReason).to.equal('not used anymore');
216216

217217
const deprecatedEnumDef = extendedSchema
218-
.getType('EnumWithDeprecatedValue');
219-
expect(deprecatedEnumDef.getValues()).to.deep.equal([
220-
{
221-
name: 'DEPRECATED',
222-
description: '',
223-
isDeprecated: true,
224-
deprecationReason: 'do not use',
225-
value: 'DEPRECATED'
226-
}
227-
]);
218+
.getType('EnumWithDeprecatedValue')
219+
.getValue('DEPRECATED');
220+
expect(deprecatedEnumDef.isDeprecated).to.equal(true);
221+
expect(deprecatedEnumDef.deprecationReason).to.equal('do not use');
228222
});
229223

230224
it('extends objects with deprecated fields', () => {

0 commit comments

Comments
 (0)