@@ -71,6 +71,11 @@ describe('coerceValue', () => {
71
71
expectValue ( result ) . to . equal ( null ) ;
72
72
} ) ;
73
73
74
+ it ( 'returns no error for NaN result' , ( ) => {
75
+ const result = coerceValue ( { value : NaN } , TestScalar ) ;
76
+ expectValue ( result ) . to . satisfy ( Number . isNaN ) ;
77
+ } ) ;
78
+
74
79
it ( 'returns an error for undefined result' , ( ) => {
75
80
const result = coerceValue ( { value : undefined } , TestScalar ) ;
76
81
expectErrors ( result ) . to . deep . equal ( [ 'Expected type TestScalar.' ] ) ;
@@ -140,9 +145,9 @@ describe('coerceValue', () => {
140
145
} ) ;
141
146
142
147
it ( 'returns an error for an invalid field' , ( ) => {
143
- const result = coerceValue ( { foo : 'abc' } , TestInputObject ) ;
148
+ const result = coerceValue ( { foo : NaN } , TestInputObject ) ;
144
149
expectErrors ( result ) . to . deep . equal ( [
145
- 'Expected type Int at value.foo. Int cannot represent non-integer value: "abc" ' ,
150
+ 'Expected type Int at value.foo. Int cannot represent non-integer value: NaN ' ,
146
151
] ) ;
147
152
} ) ;
148
153
@@ -184,7 +189,10 @@ describe('coerceValue', () => {
184
189
new GraphQLInputObjectType ( {
185
190
name : 'TestInputObject' ,
186
191
fields : {
187
- foo : { type : GraphQLInt , defaultValue } ,
192
+ foo : {
193
+ type : new GraphQLScalarType ( { name : 'TestScalar' } ) ,
194
+ defaultValue,
195
+ } ,
188
196
} ,
189
197
} ) ;
190
198
@@ -199,8 +207,15 @@ describe('coerceValue', () => {
199
207
} ) ;
200
208
201
209
it ( 'returns null as value' , ( ) => {
202
- const result = coerceValue ( { } , TestInputObject ( 7 ) ) ;
203
- expectValue ( result ) . to . deep . equal ( { foo : 7 } ) ;
210
+ const result = coerceValue ( { } , TestInputObject ( null ) ) ;
211
+ expectValue ( result ) . to . deep . equal ( { foo : null } ) ;
212
+ } ) ;
213
+
214
+ it ( 'returns NaN as value' , ( ) => {
215
+ const result = coerceValue ( { } , TestInputObject ( NaN ) ) ;
216
+ expectValue ( result )
217
+ . to . have . property ( 'foo' )
218
+ . that . satisfy ( Number . isNaN ) ;
204
219
} ) ;
205
220
} ) ;
206
221
0 commit comments