|
| 1 | +import { describe, it } from 'mocha'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { |
| 4 | + GraphQLDirective, |
| 5 | + GraphQLEnumType, |
| 6 | + GraphQLInputObjectType, |
| 7 | + GraphQLInterfaceType, |
| 8 | + GraphQLObjectType, |
| 9 | + GraphQLScalarType, |
| 10 | + GraphQLSchema, |
| 11 | + GraphQLUnionType, |
| 12 | + Source, |
| 13 | +} from '../../'; |
| 14 | + |
| 15 | +function typeOf(object) { |
| 16 | + return /(\b\w+\b)\]/.exec(Object.prototype.toString.call(object))[1]; |
| 17 | +} |
| 18 | + |
| 19 | +describe('Check to see if Symbol.toStringTag is defined on types', () => { |
| 20 | + const s = Symbol.toStringTag; |
| 21 | + const hasSymbol = o => Object.getOwnPropertySymbols(o).includes(s); |
| 22 | + |
| 23 | + it('GraphQLDirective should have Symbol.toStringTag', () => { |
| 24 | + expect(hasSymbol(GraphQLDirective.prototype)).to.equal(true); |
| 25 | + }); |
| 26 | + |
| 27 | + it('GraphQLEnumType should have Symbol.toStringTag', () => { |
| 28 | + expect(hasSymbol(GraphQLEnumType.prototype)).to.equal(true); |
| 29 | + }); |
| 30 | + |
| 31 | + it('GraphQLInputObjectType should have Symbol.toStringTag', () => { |
| 32 | + expect(hasSymbol(GraphQLInputObjectType.prototype)).to.equal(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it('GraphQLInterfaceType should have Symbol.toStringTag', () => { |
| 36 | + expect(hasSymbol(GraphQLInterfaceType.prototype)).to.equal(true); |
| 37 | + }); |
| 38 | + |
| 39 | + it('GraphQLObjectType should have Symbol.toStringTag', () => { |
| 40 | + expect(hasSymbol(GraphQLObjectType.prototype)).to.equal(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it('GraphQLScalarType should have Symbol.toStringTag', () => { |
| 44 | + expect(hasSymbol(GraphQLScalarType.prototype)).to.equal(true); |
| 45 | + }); |
| 46 | + |
| 47 | + it('GraphQLSchema should have Symbol.toStringTag', () => { |
| 48 | + expect(hasSymbol(GraphQLSchema.prototype)).to.equal(true); |
| 49 | + }); |
| 50 | + |
| 51 | + it('GraphQLUnionType should have Symbol.toStringTag', () => { |
| 52 | + expect(hasSymbol(GraphQLUnionType.prototype)).to.equal(true); |
| 53 | + }); |
| 54 | + |
| 55 | + it('Source should have Symbol.toStringTag', () => { |
| 56 | + expect(hasSymbol(Source.prototype)).to.equal(true); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
| 60 | +describe('Check to see if Symbol.toStringTag tests on instances', () => { |
| 61 | + // variables _interface and _enum have preceding underscores due to being |
| 62 | + // reserved keywords in JavaScript |
| 63 | + |
| 64 | + const schema = Object.create(GraphQLSchema.prototype); |
| 65 | + const scalar = Object.create(GraphQLScalarType.prototype); |
| 66 | + const object = Object.create(GraphQLObjectType.prototype); |
| 67 | + const _interface = Object.create(GraphQLInterfaceType.prototype); |
| 68 | + const union = Object.create(GraphQLUnionType.prototype); |
| 69 | + const _enum = Object.create(GraphQLEnumType.prototype); |
| 70 | + const inputType = Object.create(GraphQLInputObjectType.prototype); |
| 71 | + const directive = Object.create(GraphQLDirective.prototype); |
| 72 | + const source = Object.create(Source.prototype); |
| 73 | + |
| 74 | + it('should return the class name for GraphQLSchema instance', () => { |
| 75 | + expect(typeOf(schema)).to.equal(GraphQLSchema.name); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should return the class name for GraphQLScalarType instance', () => { |
| 79 | + expect(typeOf(scalar)).to.equal(GraphQLScalarType.name); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should return the class name for GraphQLObjectType instance', () => { |
| 83 | + expect(typeOf(object)).to.equal(GraphQLObjectType.name); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should return the class name for GraphQLInterfaceType instance', () => { |
| 87 | + expect(typeOf(_interface)).to.equal(GraphQLInterfaceType.name); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should return the class name for GraphQLUnionType instance', () => { |
| 91 | + expect(typeOf(union)).to.equal(GraphQLUnionType.name); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should return the class name for GraphQLEnumType instance', () => { |
| 95 | + expect(typeOf(_enum)).to.equal(GraphQLEnumType.name); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should return the class name for GraphQLInputObjectType instance', () => { |
| 99 | + expect(typeOf(inputType)).to.equal(GraphQLInputObjectType.name); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should return the class name for GraphQLDirective instance', () => { |
| 103 | + expect(typeOf(directive)).to.equal(GraphQLDirective.name); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should return the class name for Source instance', () => { |
| 107 | + expect(typeOf(source)).to.equal(Source.name); |
| 108 | + }); |
| 109 | +}); |
0 commit comments