@@ -62,31 +62,45 @@ describe('coerceValue', () => {
62
62
expectValue ( result ) . to . equal ( null ) ;
63
63
} ) ;
64
64
65
- it ( 'returns a single error for empty value' , ( ) => {
65
+ it ( 'returns a single error for empty string as value' , ( ) => {
66
66
const result = coerceValue ( '' , GraphQLInt ) ;
67
67
expectErrors ( result ) . to . deep . equal ( [
68
- 'Expected type Int; Int cannot represent non 32-bit signed integer value: (empty string)' ,
68
+ 'Expected type Int; Int cannot represent non- integer value: (empty string)' ,
69
69
] ) ;
70
70
} ) ;
71
71
72
- it ( 'returns error for float input as int' , ( ) => {
72
+ it ( 'returns a single error for 2^32 input as int' , ( ) => {
73
+ const result = coerceValue ( Math . pow ( 2 , 32 ) , GraphQLInt ) ;
74
+ expectErrors ( result ) . to . deep . equal ( [
75
+ 'Expected type Int; Int cannot represent non 32-bit signed integer value: 4294967296' ,
76
+ ] ) ;
77
+ } ) ;
78
+
79
+ it ( 'returns a single error for float input as int' , ( ) => {
73
80
const result = coerceValue ( '1.5' , GraphQLInt ) ;
74
81
expectErrors ( result ) . to . deep . equal ( [
75
82
'Expected type Int; Int cannot represent non-integer value: 1.5' ,
76
83
] ) ;
77
84
} ) ;
78
85
86
+ it ( 'returns a single error for Infinity input as int' , ( ) => {
87
+ const result = coerceValue ( Infinity , GraphQLInt ) ;
88
+ expectErrors ( result ) . to . deep . equal ( [
89
+ 'Expected type Int; Int cannot represent non-integer value: Infinity' ,
90
+ ] ) ;
91
+ } ) ;
92
+
79
93
it ( 'returns a single error for char input' , ( ) => {
80
94
const result = coerceValue ( 'a' , GraphQLInt ) ;
81
95
expectErrors ( result ) . to . deep . equal ( [
82
- 'Expected type Int; Int cannot represent non 32-bit signed integer value: a' ,
96
+ 'Expected type Int; Int cannot represent non- integer value: a' ,
83
97
] ) ;
84
98
} ) ;
85
99
86
100
it ( 'returns a single error for char input' , ( ) => {
87
101
const result = coerceValue ( 'meow' , GraphQLInt ) ;
88
102
expectErrors ( result ) . to . deep . equal ( [
89
- 'Expected type Int; Int cannot represent non 32-bit signed integer value: meow' ,
103
+ 'Expected type Int; Int cannot represent non- integer value: meow' ,
90
104
] ) ;
91
105
} ) ;
92
106
} ) ;
@@ -112,13 +126,20 @@ describe('coerceValue', () => {
112
126
expectValue ( result ) . to . equal ( null ) ;
113
127
} ) ;
114
128
115
- it ( 'returns a single error for empty value ' , ( ) => {
129
+ it ( 'returns a single error for empty string input ' , ( ) => {
116
130
const result = coerceValue ( '' , GraphQLFloat ) ;
117
131
expectErrors ( result ) . to . deep . equal ( [
118
132
'Expected type Float; Float cannot represent non numeric value: (empty string)' ,
119
133
] ) ;
120
134
} ) ;
121
135
136
+ it ( 'returns a single error for Infinity input' , ( ) => {
137
+ const result = coerceValue ( Infinity , GraphQLFloat ) ;
138
+ expectErrors ( result ) . to . deep . equal ( [
139
+ 'Expected type Float; Float cannot represent non numeric value: Infinity' ,
140
+ ] ) ;
141
+ } ) ;
142
+
122
143
it ( 'returns a single error for char input' , ( ) => {
123
144
const result = coerceValue ( 'a' , GraphQLFloat ) ;
124
145
expectErrors ( result ) . to . deep . equal ( [
@@ -191,15 +212,15 @@ describe('coerceValue', () => {
191
212
it ( 'returns no error for an invalid field' , ( ) => {
192
213
const result = coerceValue ( { foo : 'abc' } , TestInputObject ) ;
193
214
expectErrors ( result ) . to . deep . equal ( [
194
- 'Expected type Int at value.foo; Int cannot represent non 32-bit signed integer value: abc' ,
215
+ 'Expected type Int at value.foo; Int cannot represent non- integer value: abc' ,
195
216
] ) ;
196
217
} ) ;
197
218
198
219
it ( 'returns multiple errors for multiple invalid fields' , ( ) => {
199
220
const result = coerceValue ( { foo : 'abc' , bar : 'def' } , TestInputObject ) ;
200
221
expectErrors ( result ) . to . deep . equal ( [
201
- 'Expected type Int at value.foo; Int cannot represent non 32-bit signed integer value: abc' ,
202
- 'Expected type Int at value.bar; Int cannot represent non 32-bit signed integer value: def' ,
222
+ 'Expected type Int at value.foo; Int cannot represent non- integer value: abc' ,
223
+ 'Expected type Int at value.bar; Int cannot represent non- integer value: def' ,
203
224
] ) ;
204
225
} ) ;
205
226
0 commit comments