Skip to content

Commit 0f1ba1e

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 0de76ca commit 0f1ba1e

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

src/utilities/__tests__/buildASTSchema-test.js

+12-23
Original file line numberDiff line numberDiff line change
@@ -538,29 +538,18 @@ type Query {
538538
const ast = parse(body);
539539
const schema = buildASTSchema(ast);
540540

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

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

src/utilities/__tests__/extendSchema-test.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,10 @@ union SomeUnion = Foo | Biz
214214
expect(deprecatedFieldDef.deprecationReason).to.equal('not used anymore');
215215

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

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

0 commit comments

Comments
 (0)