@@ -8,9 +8,9 @@ const chunk1 = [
8
8
'' ,
9
9
'---' ,
10
10
'Content-Type: application/json' ,
11
- 'Content-Length: 64 ' ,
11
+ 'Content-Length: 142 ' ,
12
12
'' ,
13
- '{"data":{"viewer":{"currencies":null,"user":{"profile":null}}}}\n' ,
13
+ '{"data":{"viewer":{"currencies":null,"user":{"profile":null,"items":{"edges":[{"node":{"isFavorite":null}},{"node":{"isFavorite":null}}]} }}}}\n' ,
14
14
] . join ( '\r\n' ) ;
15
15
16
16
const chunk1error = [
@@ -47,6 +47,15 @@ const chunk3 = [
47
47
'Content-Length: 76' ,
48
48
'' ,
49
49
'{"path":["viewer","user","profile"],"data":{"displayName":"Steven Seagal"}}\n' ,
50
+ ] . join ( '\r\n' ) ;
51
+
52
+ const chunk4 = [
53
+ '' ,
54
+ '---' ,
55
+ 'Content-Type: application/json' ,
56
+ 'Content-Length: 78' ,
57
+ '' ,
58
+ '{"data":false,"path":["viewer","user","items","edges",1,"node","isFavorite"]}\n' ,
50
59
'' ,
51
60
'-----\r\n' ,
52
61
] . join ( '\r\n' ) ;
@@ -59,29 +68,19 @@ describe('PathResolver', function() {
59
68
} ) ;
60
69
61
70
resolver . handleChunk ( chunk1 ) ;
62
- expect ( onResponse ) . toHaveBeenCalledWith ( {
63
- data : { viewer : { currencies : null , user : { profile : null } } } ,
64
- } ) ;
71
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
72
+
65
73
onResponse . mockClear ( ) ;
66
74
resolver . handleChunk ( chunk2 ) ;
67
- expect ( onResponse ) . toHaveBeenCalledWith ( {
68
- data : {
69
- viewer : {
70
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
71
- user : { profile : null } ,
72
- } ,
73
- } ,
74
- } ) ;
75
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
76
+
75
77
onResponse . mockClear ( ) ;
76
78
resolver . handleChunk ( chunk3 ) ;
77
- expect ( onResponse ) . toHaveBeenCalledWith ( {
78
- data : {
79
- viewer : {
80
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
81
- user : { profile : { displayName : 'Steven Seagal' } } ,
82
- } ,
83
- } ,
84
- } ) ;
79
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
80
+
81
+ onResponse . mockClear ( ) ;
82
+ resolver . handleChunk ( chunk4 ) ;
83
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
85
84
} ) ;
86
85
87
86
it ( 'should work when chunks are split' , function ( ) {
@@ -90,8 +89,6 @@ describe('PathResolver', function() {
90
89
onResponse,
91
90
} ) ;
92
91
93
- console . log ( 'chunk1.length' , chunk1 . length ) ;
94
-
95
92
const chunk1a = chunk1 . substr ( 0 , 35 ) ;
96
93
const chunk1b = chunk1 . substr ( 35 , 80 ) ;
97
94
const chunk1c = chunk1 . substr ( 35 + 80 ) ;
@@ -101,9 +98,7 @@ describe('PathResolver', function() {
101
98
resolver . handleChunk ( chunk1b ) ;
102
99
expect ( onResponse ) . not . toHaveBeenCalled ( ) ;
103
100
resolver . handleChunk ( chunk1c ) ;
104
- expect ( onResponse ) . toHaveBeenCalledWith ( {
105
- data : { viewer : { currencies : null , user : { profile : null } } } ,
106
- } ) ;
101
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
107
102
onResponse . mockClear ( ) ;
108
103
109
104
const chunk2a = chunk2 . substr ( 0 , 35 ) ;
@@ -112,14 +107,7 @@ describe('PathResolver', function() {
112
107
resolver . handleChunk ( chunk2a ) ;
113
108
expect ( onResponse ) . not . toHaveBeenCalled ( ) ;
114
109
resolver . handleChunk ( chunk2b ) ;
115
- expect ( onResponse ) . toHaveBeenCalledWith ( {
116
- data : {
117
- viewer : {
118
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
119
- user : { profile : null } ,
120
- } ,
121
- } ,
122
- } ) ;
110
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
123
111
onResponse . mockClear ( ) ;
124
112
125
113
const chunk3a = chunk3 . substr ( 0 , 10 ) ;
@@ -131,14 +119,7 @@ describe('PathResolver', function() {
131
119
resolver . handleChunk ( chunk3b ) ;
132
120
expect ( onResponse ) . not . toHaveBeenCalled ( ) ;
133
121
resolver . handleChunk ( chunk3c ) ;
134
- expect ( onResponse ) . toHaveBeenCalledWith ( {
135
- data : {
136
- viewer : {
137
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
138
- user : { profile : { displayName : 'Steven Seagal' } } ,
139
- } ,
140
- } ,
141
- } ) ;
122
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
142
123
} ) ;
143
124
144
125
it ( 'should work when chunks are combined' , function ( ) {
@@ -148,17 +129,8 @@ describe('PathResolver', function() {
148
129
} ) ;
149
130
150
131
resolver . handleChunk ( chunk1 + chunk2 ) ;
151
- expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
152
- data : { viewer : { currencies : null , user : { profile : null } } } ,
153
- } ) ;
154
- expect ( onResponse . mock . calls [ 1 ] [ 0 ] ) . toEqual ( {
155
- data : {
156
- viewer : {
157
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
158
- user : { profile : null } ,
159
- } ,
160
- } ,
161
- } ) ;
132
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
133
+ expect ( onResponse . mock . calls [ 1 ] [ 0 ] ) . toMatchSnapshot ( ) ;
162
134
} ) ;
163
135
164
136
it ( 'should work when chunks are combined and split' , function ( ) {
@@ -172,30 +144,14 @@ describe('PathResolver', function() {
172
144
const chunk3c = chunk3 . substr ( 11 + 20 ) ;
173
145
174
146
resolver . handleChunk ( chunk1 + chunk2 + chunk3a ) ;
175
- expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
176
- data : { viewer : { currencies : null , user : { profile : null } } } ,
177
- } ) ;
178
- expect ( onResponse . mock . calls [ 1 ] [ 0 ] ) . toEqual ( {
179
- data : {
180
- viewer : {
181
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
182
- user : { profile : null } ,
183
- } ,
184
- } ,
185
- } ) ;
147
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
148
+ expect ( onResponse . mock . calls [ 1 ] [ 0 ] ) . toMatchSnapshot ( ) ;
186
149
onResponse . mockClear ( ) ;
187
150
188
151
resolver . handleChunk ( chunk3b ) ;
189
152
expect ( onResponse ) . not . toHaveBeenCalled ( ) ;
190
153
resolver . handleChunk ( chunk3c ) ;
191
- expect ( onResponse ) . toHaveBeenCalledWith ( {
192
- data : {
193
- viewer : {
194
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
195
- user : { profile : { displayName : 'Steven Seagal' } } ,
196
- } ,
197
- } ,
198
- } ) ;
154
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
199
155
} ) ;
200
156
201
157
it ( 'should work when chunks are combined across boundaries' , function ( ) {
@@ -208,20 +164,10 @@ describe('PathResolver', function() {
208
164
const chunk2b = chunk2 . substring ( 35 ) ;
209
165
210
166
resolver . handleChunk ( chunk1 + chunk2a ) ;
211
- expect ( onResponse ) . toHaveBeenCalledWith ( {
212
- data : { viewer : { currencies : null , user : { profile : null } } } ,
213
- } ) ;
167
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
214
168
onResponse . mockClear ( ) ;
215
169
resolver . handleChunk ( chunk2b ) ;
216
-
217
- expect ( onResponse ) . toHaveBeenCalledWith ( {
218
- data : {
219
- viewer : {
220
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
221
- user : { profile : null } ,
222
- } ,
223
- } ,
224
- } ) ;
170
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
225
171
} ) ;
226
172
227
173
it ( 'should merge errors' , function ( ) {
@@ -231,32 +177,12 @@ describe('PathResolver', function() {
231
177
} ) ;
232
178
233
179
resolver . handleChunk ( chunk1error ) ;
234
- expect ( onResponse ) . toHaveBeenCalledWith ( {
235
- data : { viewer : { currencies : null , user : { profile : null } } } ,
236
- errors : [ { message : 'Very Bad Error' } ] ,
237
- } ) ;
180
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
238
181
onResponse . mockClear ( ) ;
239
182
resolver . handleChunk ( chunk2error ) ;
240
- expect ( onResponse ) . toHaveBeenCalledWith ( {
241
- data : {
242
- viewer : {
243
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
244
- user : { profile : null } ,
245
- } ,
246
- } ,
247
- errors : [ { message : 'Very Bad Error' } , { message : 'Not So Bad Error' } ] ,
248
- } ) ;
183
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
249
184
onResponse . mockClear ( ) ;
250
185
resolver . handleChunk ( chunk3 ) ;
251
- expect ( onResponse ) . toHaveBeenCalledWith ( {
252
- data : {
253
- viewer : {
254
- currencies : [ 'USD' , 'GBP' , 'EUR' , 'CAD' , 'AUD' , 'CHF' , '😂' ] ,
255
- user : { profile : { displayName : 'Steven Seagal' } } ,
256
- } ,
257
- } ,
258
- errors : [ { message : 'Very Bad Error' } , { message : 'Not So Bad Error' } ] ,
259
- } ) ;
186
+ expect ( onResponse . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( ) ;
260
187
} ) ;
261
- it ( 'should work' , function ( ) { } ) ;
262
188
} ) ;
0 commit comments