Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move 'Object.toString' tests to the appropriate files #1723

Merged
merged 1 commit into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/language/__tests__/source-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { Source } from '../source';

describe('Source', () => {
it('can be Object.toStringified', () => {
const source = new Source('');

expect(Object.prototype.toString.call(source)).to.equal('[object Source]');
});
});
81 changes: 49 additions & 32 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,38 +122,6 @@ describe('Type System: Example', () => {
});
});

it('stringifies simple types', () => {
expect(String(ScalarType)).to.equal('Scalar');
expect(String(ObjectType)).to.equal('Object');
expect(String(InterfaceType)).to.equal('Interface');
expect(String(UnionType)).to.equal('Union');
expect(String(EnumType)).to.equal('Enum');
expect(String(InputObjectType)).to.equal('InputObject');

expect(String(NonNullScalarType)).to.equal('Scalar!');
expect(String(ListOfScalarsType)).to.equal('[Scalar]');
expect(String(NonNullListofScalars)).to.equal('[Scalar]!');
expect(String(ListOfNonNullScalarsType)).to.equal('[Scalar!]');
expect(String(GraphQLList(ListOfScalarsType))).to.equal('[[Scalar]]');
});

it('JSON stringifies simple types', () => {
expect(JSON.stringify(ScalarType)).to.equal('"Scalar"');
expect(JSON.stringify(ObjectType)).to.equal('"Object"');
expect(JSON.stringify(InterfaceType)).to.equal('"Interface"');
expect(JSON.stringify(UnionType)).to.equal('"Union"');
expect(JSON.stringify(EnumType)).to.equal('"Enum"');
expect(JSON.stringify(InputObjectType)).to.equal('"InputObject"');

expect(JSON.stringify(NonNullScalarType)).to.equal('"Scalar!"');
expect(JSON.stringify(ListOfScalarsType)).to.equal('"[Scalar]"');
expect(JSON.stringify(NonNullListofScalars)).to.equal('"[Scalar]!"');
expect(JSON.stringify(ListOfNonNullScalarsType)).to.equal('"[Scalar!]"');
expect(JSON.stringify(GraphQLList(ListOfScalarsType))).to.equal(
'"[[Scalar]]"',
);
});

it('allows a thunk for Union member types', () => {
const union = new GraphQLUnionType({
name: 'ThunkUnion',
Expand Down Expand Up @@ -939,3 +907,52 @@ describe('Type System: NonNull must only accept non-nullable types', () => {
);
});
});

describe('Type System: test utility methods', () => {
it('stringifies types', () => {
expect(String(ScalarType)).to.equal('Scalar');
expect(String(ObjectType)).to.equal('Object');
expect(String(InterfaceType)).to.equal('Interface');
expect(String(UnionType)).to.equal('Union');
expect(String(EnumType)).to.equal('Enum');
expect(String(InputObjectType)).to.equal('InputObject');

expect(String(NonNullScalarType)).to.equal('Scalar!');
expect(String(ListOfScalarsType)).to.equal('[Scalar]');
expect(String(NonNullListofScalars)).to.equal('[Scalar]!');
expect(String(ListOfNonNullScalarsType)).to.equal('[Scalar!]');
expect(String(GraphQLList(ListOfScalarsType))).to.equal('[[Scalar]]');
});

it('JSON.stringifies types', () => {
expect(JSON.stringify(ScalarType)).to.equal('"Scalar"');
expect(JSON.stringify(ObjectType)).to.equal('"Object"');
expect(JSON.stringify(InterfaceType)).to.equal('"Interface"');
expect(JSON.stringify(UnionType)).to.equal('"Union"');
expect(JSON.stringify(EnumType)).to.equal('"Enum"');
expect(JSON.stringify(InputObjectType)).to.equal('"InputObject"');

expect(JSON.stringify(NonNullScalarType)).to.equal('"Scalar!"');
expect(JSON.stringify(ListOfScalarsType)).to.equal('"[Scalar]"');
expect(JSON.stringify(NonNullListofScalars)).to.equal('"[Scalar]!"');
expect(JSON.stringify(ListOfNonNullScalarsType)).to.equal('"[Scalar!]"');
expect(JSON.stringify(GraphQLList(ListOfScalarsType))).to.equal(
'"[[Scalar]]"',
);
});

it('Object.toStringifies types', () => {
function toString(obj) {
return Object.prototype.toString.call(obj);
}

expect(toString(ScalarType)).to.equal('[object GraphQLScalarType]');
expect(toString(ObjectType)).to.equal('[object GraphQLObjectType]');
expect(toString(InterfaceType)).to.equal('[object GraphQLInterfaceType]');
expect(toString(UnionType)).to.equal('[object GraphQLUnionType]');
expect(toString(EnumType)).to.equal('[object GraphQLEnumType]');
expect(toString(InputObjectType)).to.equal(
'[object GraphQLInputObjectType]',
);
});
});
5 changes: 4 additions & 1 deletion src/type/__tests__/directive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ describe('Type System: Directive', () => {
});
});

it('can be stringified and JSON.stringified', () => {
it('can be stringified, JSON.stringified and Object.toStingified', () => {
const directive = new GraphQLDirective({
name: 'Foo',
locations: ['QUERY'],
});

expect(String(directive)).to.equal('@Foo');
expect(JSON.stringify(directive)).to.equal('"@Foo"');
expect(Object.prototype.toString.call(directive)).to.equal(
'[object GraphQLDirective]',
);
});

it('reject an unnamed directive', () => {
Expand Down
8 changes: 8 additions & 0 deletions src/type/__tests__/schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ describe('Type System: Schema', () => {
});
});

it('can be Object.toStringified', () => {
const schema = new GraphQLSchema({});

expect(Object.prototype.toString.call(schema)).to.equal(
'[object GraphQLSchema]',
);
});

describe('Validity', () => {
describe('when not assumed valid', () => {
it('configures the schema to still needing validation', () => {
Expand Down
118 changes: 0 additions & 118 deletions src/type/__tests__/toStringTag-test.js

This file was deleted.