Skip to content

Commit

Permalink
Tests: 'expect(...).to.eql' => 'expect(...).to.deep.equal' (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 1, 2019
1 parent fbd9c47 commit 0addc5b
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions src/utilities/__tests__/findBreakingChanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ describe('findBreakingChanges', () => {
field1: String
}
`);
expect(findRemovedTypes(oldSchema, newSchema)).to.eql([
expect(findRemovedTypes(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.TYPE_REMOVED,
description: 'Type1 was removed.',
},
]);
expect(findRemovedTypes(oldSchema, oldSchema)).to.eql([]);
expect(findRemovedTypes(oldSchema, oldSchema)).to.deep.equal([]);
});

it('should detect if a type changed its type', () => {
Expand All @@ -102,7 +102,7 @@ describe('findBreakingChanges', () => {
field1: String
}
`);
expect(findTypesThatChangedKind(oldSchema, newSchema)).to.eql([
expect(findTypesThatChangedKind(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.TYPE_CHANGED_KIND,
description: 'Type1 changed from an Interface type to a Union type.',
Expand Down Expand Up @@ -175,7 +175,11 @@ describe('findBreakingChanges', () => {
}
`);

const expectedFieldChanges = [
const changes = findFieldsThatChangedTypeOnObjectOrInterfaceTypes(
oldSchema,
newSchema,
);
expect(changes).to.deep.equal([
{
type: BreakingChangeType.FIELD_REMOVED,
description: 'Type1.field2 was removed.',
Expand Down Expand Up @@ -228,10 +232,7 @@ describe('findBreakingChanges', () => {
type: BreakingChangeType.FIELD_CHANGED_KIND,
description: 'Type1.field18 changed type from [[Int!]!] to [[Int!]].',
},
];
expect(
findFieldsThatChangedTypeOnObjectOrInterfaceTypes(oldSchema, newSchema),
).to.eql(expectedFieldChanges);
]);
});

it('should detect if fields on input types changed kind or were removed', () => {
Expand Down Expand Up @@ -282,7 +283,11 @@ describe('findBreakingChanges', () => {
}
`);

const expectedFieldChanges = [
const { breakingChanges } = findFieldsThatChangedTypeOnInputObjectTypes(
oldSchema,
newSchema,
);
expect(breakingChanges).to.deep.equal([
{
type: BreakingChangeType.FIELD_CHANGED_KIND,
description: 'InputType1.field1 changed type from String to Int.',
Expand Down Expand Up @@ -328,11 +333,7 @@ describe('findBreakingChanges', () => {
description:
'InputType1.field15 changed type from [[Int]!] to [[Int!]!].',
},
];
expect(
findFieldsThatChangedTypeOnInputObjectTypes(oldSchema, newSchema)
.breakingChanges,
).to.eql(expectedFieldChanges);
]);
});

it('should detect if a required field is added to an input type', () => {
Expand All @@ -359,17 +360,17 @@ describe('findBreakingChanges', () => {
}
`);

const expectedFieldChanges = [
const { breakingChanges } = findFieldsThatChangedTypeOnInputObjectTypes(
oldSchema,
newSchema,
);
expect(breakingChanges).to.deep.equal([
{
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
description:
'A required field requiredField on input type InputType1 was added.',
},
];
expect(
findFieldsThatChangedTypeOnInputObjectTypes(oldSchema, newSchema)
.breakingChanges,
).to.eql(expectedFieldChanges);
]);
});

it('should detect if a type was removed from a union type', () => {
Expand Down Expand Up @@ -404,7 +405,7 @@ describe('findBreakingChanges', () => {
}
`);

expect(findTypesRemovedFromUnions(oldSchema, newSchema)).to.eql([
expect(findTypesRemovedFromUnions(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
description: 'Type2 was removed from union type UnionType1.',
Expand Down Expand Up @@ -437,7 +438,7 @@ describe('findBreakingChanges', () => {
}
`);

expect(findValuesRemovedFromEnums(oldSchema, newSchema)).to.eql([
expect(findValuesRemovedFromEnums(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
description: 'VALUE1 was removed from enum type EnumType1.',
Expand Down Expand Up @@ -478,7 +479,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).breakingChanges).to.eql([
const { breakingChanges } = findArgChanges(oldSchema, newSchema);
expect(breakingChanges).to.deep.equal([
{
type: BreakingChangeType.ARG_REMOVED,
description: 'Interface1.field1 arg arg1 was removed',
Expand Down Expand Up @@ -547,7 +549,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).breakingChanges).to.eql([
const { breakingChanges } = findArgChanges(oldSchema, newSchema);
expect(breakingChanges).to.deep.equal([
{
type: BreakingChangeType.ARG_CHANGED_KIND,
description:
Expand Down Expand Up @@ -637,7 +640,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).breakingChanges).to.eql([
const { breakingChanges } = findArgChanges(oldSchema, newSchema);
expect(breakingChanges).to.deep.equal([
{
type: BreakingChangeType.REQUIRED_ARG_ADDED,
description: 'A required arg newRequiredArg on Type1.field1 was added',
Expand Down Expand Up @@ -674,7 +678,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).breakingChanges).to.eql([]);
const { breakingChanges } = findArgChanges(oldSchema, newSchema);
expect(breakingChanges).to.deep.equal([]);
});

it('should consider args that move away from NonNull as non-breaking', () => {
Expand All @@ -698,7 +703,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).breakingChanges).to.eql([]);
const { breakingChanges } = findArgChanges(oldSchema, newSchema);
expect(breakingChanges).to.deep.equal([]);
});

it('should detect interfaces removed from types', () => {
Expand Down Expand Up @@ -726,7 +732,8 @@ describe('findBreakingChanges', () => {
}
`);

expect(findInterfacesRemovedFromObjectTypes(oldSchema, newSchema)).to.eql([
const changes = findInterfacesRemovedFromObjectTypes(oldSchema, newSchema);
expect(changes).to.deep.equal([
{
description: 'Type1 no longer implements interface Interface1.',
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
Expand Down Expand Up @@ -833,7 +840,8 @@ describe('findBreakingChanges', () => {
}
`);

const expectedBreakingChanges = [
const changes = findBreakingChanges(oldSchema, newSchema);
expect(changes).to.deep.equal([
{
type: BreakingChangeType.TYPE_REMOVED,
description: 'Int was removed.',
Expand Down Expand Up @@ -897,10 +905,7 @@ describe('findBreakingChanges', () => {
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
description: 'QUERY was removed from DirectiveName',
},
];
expect(findBreakingChanges(oldSchema, newSchema)).to.eql(
expectedBreakingChanges,
);
]);
});

it('should detect if a directive was explicitly removed', () => {
Expand All @@ -913,7 +918,7 @@ describe('findBreakingChanges', () => {
directive @DirectiveThatStays on FIELD_DEFINITION
`);

expect(findRemovedDirectives(oldSchema, newSchema)).to.eql([
expect(findRemovedDirectives(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.DIRECTIVE_REMOVED,
description: `DirectiveThatIsRemoved was removed`,
Expand All @@ -928,7 +933,7 @@ describe('findBreakingChanges', () => {
directives: [GraphQLSkipDirective, GraphQLIncludeDirective],
});

expect(findRemovedDirectives(oldSchema, newSchema)).to.eql([
expect(findRemovedDirectives(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.DIRECTIVE_REMOVED,
description: `${GraphQLDeprecatedDirective.name} was removed`,
Expand All @@ -945,7 +950,7 @@ describe('findBreakingChanges', () => {
directive @DirectiveWithArg on FIELD_DEFINITION
`);

expect(findRemovedDirectiveArgs(oldSchema, newSchema)).to.eql([
expect(findRemovedDirectiveArgs(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.DIRECTIVE_ARG_REMOVED,
description: 'arg1 was removed from DirectiveWithArg',
Expand All @@ -966,7 +971,7 @@ describe('findBreakingChanges', () => {
) on FIELD_DEFINITION
`);

expect(findAddedNonNullDirectiveArgs(oldSchema, newSchema)).to.eql([
expect(findAddedNonNullDirectiveArgs(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
description:
Expand All @@ -986,7 +991,7 @@ describe('findBreakingChanges', () => {
locations: [DirectiveLocation.FIELD_DEFINITION],
});

expect(findRemovedLocationsForDirective(d1, d2)).to.eql([
expect(findRemovedLocationsForDirective(d1, d2)).to.deep.equal([
DirectiveLocation.QUERY,
]);
});
Expand All @@ -1000,7 +1005,7 @@ describe('findBreakingChanges', () => {
directive @DirectiveName on FIELD_DEFINITION
`);

expect(findRemovedDirectiveLocations(oldSchema, newSchema)).to.eql([
expect(findRemovedDirectiveLocations(oldSchema, newSchema)).to.deep.equal([
{
type: BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
description: 'QUERY was removed from DirectiveName',
Expand Down Expand Up @@ -1032,7 +1037,8 @@ describe('findDangerousChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).dangerousChanges).to.eql([
const { dangerousChanges } = findArgChanges(oldSchema, newSchema);
expect(dangerousChanges).to.deep.equal([
{
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
description: 'Type1.field1 arg name has changed defaultValue',
Expand Down Expand Up @@ -1065,7 +1071,7 @@ describe('findDangerousChanges', () => {
}
`);

expect(findValuesAddedToEnums(oldSchema, newSchema)).to.eql([
expect(findValuesAddedToEnums(oldSchema, newSchema)).to.deep.equal([
{
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
description: 'VALUE2 was added to enum type EnumType1.',
Expand Down Expand Up @@ -1098,7 +1104,8 @@ describe('findDangerousChanges', () => {
}
`);

expect(findInterfacesAddedToObjectTypes(oldSchema, newSchema)).to.eql([
const changes = findInterfacesAddedToObjectTypes(oldSchema, newSchema);
expect(changes).to.deep.equal([
{
description: 'Interface1 added to interfaces implemented by Type1.',
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
Expand Down Expand Up @@ -1135,7 +1142,7 @@ describe('findDangerousChanges', () => {
}
`);

expect(findTypesAddedToUnions(oldSchema, newSchema)).to.eql([
expect(findTypesAddedToUnions(oldSchema, newSchema)).to.deep.equal([
{
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
description: 'Type2 was added to union type UnionType1.',
Expand Down Expand Up @@ -1165,18 +1172,17 @@ describe('findDangerousChanges', () => {
}
`);

const expectedFieldChanges = [
const { dangerousChanges } = findFieldsThatChangedTypeOnInputObjectTypes(
oldSchema,
newSchema,
);
expect(dangerousChanges).to.deep.equal([
{
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
description:
'An optional field field2 on input type InputType1 was added.',
},
];

expect(
findFieldsThatChangedTypeOnInputObjectTypes(oldSchema, newSchema)
.dangerousChanges,
).to.eql(expectedFieldChanges);
]);
});

it('should find all dangerous changes', () => {
Expand Down Expand Up @@ -1239,7 +1245,8 @@ describe('findDangerousChanges', () => {
}
`);

const expectedDangerousChanges = [
const changes = findDangerousChanges(oldSchema, newSchema);
expect(changes).to.deep.equal([
{
description: 'Type1.field1 arg name has changed defaultValue',
type: 'ARG_DEFAULT_VALUE_CHANGE',
Expand All @@ -1258,11 +1265,7 @@ describe('findDangerousChanges', () => {
description:
'TypeInUnion2 was added to union type UnionTypeThatGainsAType.',
},
];

expect(findDangerousChanges(oldSchema, newSchema)).to.eql(
expectedDangerousChanges,
);
]);
});

it('should detect if an optional field argument was added', () => {
Expand All @@ -1286,7 +1289,8 @@ describe('findDangerousChanges', () => {
}
`);

expect(findArgChanges(oldSchema, newSchema).dangerousChanges).to.eql([
const { dangerousChanges } = findArgChanges(oldSchema, newSchema);
expect(dangerousChanges).to.deep.equal([
{
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
description: 'An optional arg arg2 on Type1.field1 was added',
Expand Down

0 comments on commit 0addc5b

Please sign in to comment.