1- import should from 'should' ;
1+ import * as chai from 'chai' ;
2+ chai . should ( ) ;
23import sinon from 'sinon' ;
34import nock from 'nock' ;
45import request from '../../lib/request.js' ;
@@ -28,7 +29,7 @@ describe('request', () => {
2829 } ;
2930
3031 return request . get ( { url, options} ) . then ( ( ) => {
31- scope . isDone ( ) . should . be . eql ( true ) ;
32+ scope . isDone ( ) . should . eql ( true ) ;
3233 } ) ;
3334 } ) ;
3435
@@ -42,7 +43,7 @@ describe('request', () => {
4243 . reply ( 200 ) ;
4344
4445 return request . get ( { url, referer} ) . then ( ( ) => {
45- scope . isDone ( ) . should . be . eql ( true ) ;
46+ scope . isDone ( ) . should . eql ( true ) ;
4647 } ) ;
4748 } ) ;
4849
@@ -52,11 +53,11 @@ describe('request', () => {
5253 let handlerStub = sinon . stub ( ) . resolves ( '' ) ;
5354
5455 return request . get ( { url, afterResponse : handlerStub } ) . then ( ( ) => {
55- scope . isDone ( ) . should . be . eql ( true ) ;
56- should ( handlerStub . calledOnce ) . be . eql ( true ) ;
56+ scope . isDone ( ) . should . eql ( true ) ;
57+ handlerStub . calledOnce . should . eql ( true ) ;
5758 const afterResponseArgs = handlerStub . getCall ( 0 ) . args [ 0 ] ;
58- should ( afterResponseArgs . response . body ) . be . eql ( 'TEST BODY' ) ;
59- should ( afterResponseArgs . response . headers ) . be . eql ( { } ) ;
59+ afterResponseArgs . response . body . should . eql ( 'TEST BODY' ) ;
60+ afterResponseArgs . response . headers . should . eql ( { } ) ;
6061 } ) ;
6162 } ) ;
6263
@@ -71,9 +72,9 @@ describe('request', () => {
7172 } ) ;
7273
7374 return request . get ( { url, afterResponse : handlerStub } ) . then ( ( data ) => {
74- should ( data . body ) . be . eql ( 'a' ) ;
75- should ( data . metadata ) . be . eql ( 'b' ) ;
76- should ( data . encoding ) . be . eql ( 'utf8' ) ;
75+ data . body . should . eql ( 'a' ) ;
76+ data . metadata . should . eql ( 'b' ) ;
77+ data . encoding . should . eql ( 'utf8' ) ;
7778 } ) ;
7879 } ) ;
7980
@@ -85,9 +86,9 @@ describe('request', () => {
8586 } ) ;
8687
8788 return request . get ( { url, afterResponse : handlerStub } ) . then ( ( data ) => {
88- should ( data . body ) . be . eql ( 'a' ) ;
89- should ( data . metadata ) . be . eql ( null ) ;
90- should ( data . encoding ) . be . eql ( 'binary' ) ;
89+ data . body . should . eql ( 'a' ) ;
90+ ( data . metadata === null ) . should . be . true ;
91+ data . encoding . should . eql ( 'binary' ) ;
9192 } ) ;
9293 } ) ;
9394
@@ -97,8 +98,8 @@ describe('request', () => {
9798 const handlerStub = sinon . stub ( ) . resolves ( 'test body' ) ;
9899
99100 return request . get ( { url, afterResponse : handlerStub } ) . then ( ( data ) => {
100- should ( data . body ) . be . eql ( 'test body' ) ;
101- should ( data . metadata ) . be . eql ( null ) ;
101+ data . body . should . eql ( 'test body' ) ;
102+ ( data . metadata === null ) . should . be . true ;
102103 } ) ;
103104 } ) ;
104105
@@ -108,10 +109,10 @@ describe('request', () => {
108109 const handlerStub = sinon . stub ( ) . resolves ( [ '1' , '2' ] ) ;
109110
110111 return request . get ( { url, afterResponse : handlerStub } ) . then ( ( ) => {
111- should ( true ) . be . eql ( false ) ;
112+ true . should . eql ( false ) ;
112113 } ) . catch ( ( e ) => {
113- should ( e ) . be . instanceOf ( Error ) ;
114- should ( e . message ) . match ( / W r o n g r e s p o n s e h a n d l e r r e s u l t . E x p e c t e d s t r i n g o r o b j e c t , b u t r e c e i v e d / ) ;
114+ e . should . be . instanceOf ( Error ) ;
115+ e . message . should . match ( / W r o n g r e s p o n s e h a n d l e r r e s u l t . E x p e c t e d s t r i n g o r o b j e c t , b u t r e c e i v e d / ) ;
115116 } ) ;
116117 } ) ;
117118 } ) ;
@@ -123,11 +124,13 @@ describe('request', () => {
123124 } ) ;
124125
125126 return request . get ( { url} ) . then ( ( data ) => {
126- data . should . have . properties ( [ 'url' , 'body' , 'mimeType' ] ) ;
127- data . url . should . be . eql ( 'http://www.google.com/' ) ;
128- data . body . should . be . eql ( 'Hello from Google!' ) ;
129- data . mimeType . should . be . eql ( 'text/html' ) ;
130- data . encoding . should . be . eql ( 'utf8' ) ;
127+ data . should . have . property ( 'url' ) ;
128+ data . should . have . property ( 'body' ) ;
129+ data . should . have . property ( 'mimeType' ) ;
130+ data . url . should . eql ( 'http://www.google.com/' ) ;
131+ data . body . should . eql ( 'Hello from Google!' ) ;
132+ data . mimeType . should . eql ( 'text/html' ) ;
133+ data . encoding . should . eql ( 'utf8' ) ;
131134 } ) ;
132135 } ) ;
133136
@@ -136,11 +139,11 @@ describe('request', () => {
136139 nock ( url ) . get ( '/' ) . reply ( 200 , 'Hello from Google!' , { } ) ;
137140
138141 return request . get ( { url} ) . then ( ( data ) => {
139- data . should . have . properties ( [ 'url' , 'body' , 'mimeType' ] ) ;
140- data . url . should . be . eql ( 'http://www.google.com/' ) ;
141- data . body . should . be . eql ( 'Hello from Google!' ) ;
142- data . encoding . should . be . eql ( 'binary' ) ;
143- should ( data . mimeType ) . be . eql ( null ) ;
142+ data . should . include . all . keys ( [ 'url' , 'body' , 'mimeType' , 'encoding '] ) ;
143+ data . url . should . eql ( 'http://www.google.com/' ) ;
144+ data . body . should . eql ( 'Hello from Google!' ) ;
145+ data . encoding . should . eql ( 'binary' ) ;
146+ data . should . have . property ( 'mimeType' , null ) ;
144147 } ) ;
145148 } ) ;
146149} ) ;
@@ -149,23 +152,23 @@ describe('get encoding', () => {
149152 it ( 'should return binary by default' , ( ) => {
150153 const result = request . getEncoding ( null ) ;
151154
152- should ( result ) . be . eql ( 'binary' ) ;
155+ result . should . eql ( 'binary' ) ;
153156 } ) ;
154157
155158 it ( 'should return binary when no content-type header supplies' , ( ) => {
156159 const result = request . getEncoding ( {
157160 headers : { }
158161 } ) ;
159162
160- should ( result ) . be . eql ( 'binary' ) ;
163+ result . should . eql ( 'binary' ) ;
161164 } ) ;
162165
163166 it ( 'should return binary when content type header doesn\'t include utf-8' , ( ) => {
164167 const result = request . getEncoding ( {
165168 headers : { }
166169 } ) ;
167170
168- should ( result ) . be . eql ( 'binary' ) ;
171+ result . should . eql ( 'binary' ) ;
169172 } ) ;
170173
171174 it ( 'should return binary when content type header doesn\'t include utf-8' , ( ) => {
@@ -175,7 +178,7 @@ describe('get encoding', () => {
175178 }
176179 } ) ;
177180
178- should ( result ) . be . eql ( 'binary' ) ;
181+ result . should . eql ( 'binary' ) ;
179182 } ) ;
180183
181184 it ( 'should return utf8 when content type includes utf-8' , ( ) => {
@@ -185,15 +188,15 @@ describe('get encoding', () => {
185188 }
186189 } ) ;
187190
188- should ( result ) . be . eql ( 'utf8' ) ;
191+ result . should . eql ( 'utf8' ) ;
189192 } ) ;
190193
191194 it ( 'should return utf8 response object includes it' , ( ) => {
192195 const result = request . getEncoding ( {
193196 encoding : 'utf8'
194197 } ) ;
195198
196- should ( result ) . be . eql ( 'utf8' ) ;
199+ result . should . eql ( 'utf8' ) ;
197200 } ) ;
198201} ) ;
199202
@@ -203,10 +206,10 @@ describe('transformResult', () => {
203206 request . transformResult ( [ 1 , 2 , 3 ] ) ;
204207
205208 // We shouldn't get here.
206- should ( true ) . eql ( false ) ;
209+ true . should . eql ( false ) ;
207210 } catch ( e ) {
208- should ( e ) . be . instanceOf ( Error ) ;
209- should ( e . message ) . eql ( 'Wrong response handler result. Expected string or object, but received array' ) ;
211+ e . should . be . instanceOf ( Error ) ;
212+ e . message . should . eql ( 'Wrong response handler result. Expected string or object, but received array' ) ;
210213 }
211214 } ) ;
212215
@@ -215,10 +218,10 @@ describe('transformResult', () => {
215218 request . transformResult ( new Error ( 'Oh no' ) ) ;
216219
217220 // We shouldn't get here.
218- should ( true ) . eql ( false ) ;
221+ true . should . eql ( false ) ;
219222 } catch ( e ) {
220- should ( e ) . be . instanceOf ( Error ) ;
221- should ( e . message ) . eql ( 'Oh no' ) ;
223+ e . should . be . instanceOf ( Error ) ;
224+ e . message . should . eql ( 'Oh no' ) ;
222225 }
223226 } ) ;
224227
@@ -227,10 +230,10 @@ describe('transformResult', () => {
227230 request . transformResult ( true ) ;
228231
229232 // We shouldn't get here.
230- should ( true ) . eql ( false ) ;
233+ true . should . eql ( false ) ;
231234 } catch ( e ) {
232- should ( e ) . be . instanceOf ( Error ) ;
233- should ( e . message ) . eql ( 'Wrong response handler result. Expected string or object, but received boolean' ) ;
235+ e . should . be . instanceOf ( Error ) ;
236+ e . message . should . eql ( 'Wrong response handler result. Expected string or object, but received boolean' ) ;
234237 }
235238 } ) ;
236239
@@ -241,9 +244,9 @@ describe('transformResult', () => {
241244 metadata : { foo : 'bar' }
242245 } ) ;
243246
244- should ( result ) . have . property ( 'body' , 'SOME BODY' ) ;
245- should ( result ) . have . property ( 'encoding' , 'utf8' ) ;
246- should ( result ) . have . property ( 'metadata' , { foo : 'bar' } ) ;
247+ result . should . have . property ( 'body' , 'SOME BODY' ) ;
248+ result . should . have . property ( 'encoding' , 'utf8' ) ;
249+ result . should . have . property ( 'metadata' ) . that . eql ( { foo : 'bar' } ) ;
247250 } ) ;
248251
249252 it ( 'should handle object with empty body string' , ( ) => {
@@ -252,38 +255,36 @@ describe('transformResult', () => {
252255 encoding : 'utf8' ,
253256 } ) ;
254257
255- should ( result ) . have . property ( 'body' , '' ) ;
256- should ( result ) . have . property ( 'encoding' , 'utf8' ) ;
257- should ( result ) . have . property ( 'metadata' , null ) ;
258+ result . should . have . property ( 'body' , '' ) ;
259+ result . should . have . property ( 'encoding' , 'utf8' ) ;
260+ result . should . have . property ( 'metadata' , null ) ;
258261 } ) ;
259262
260263 it ( 'should handle object with defaults and buffer body' , ( ) => {
261264 const result = request . transformResult ( {
262265 body : Buffer . from ( 'SOME BODY' ) ,
263266 } ) ;
264267
265- should ( result ) . have . property ( 'body' , 'SOME BODY' ) ;
266- should ( result ) . have . property ( 'encoding' , 'binary' ) ;
267- should ( result ) . have . property ( 'metadata' , null ) ;
268+ result . should . have . property ( 'body' , 'SOME BODY' ) ;
269+ result . should . have . property ( 'encoding' , 'binary' ) ;
270+ result . should . have . property ( 'metadata' , null ) ;
268271 } ) ;
269272
270273 it ( 'should handle raw string input' , ( ) => {
271274 const result = request . transformResult ( 'SOME BODY' ) ;
272275
273- should ( result ) . have . property ( 'body' , 'SOME BODY' ) ;
274- should ( result ) . have . property ( 'encoding' , 'binary' ) ;
275- should ( result ) . have . property ( 'metadata' , null ) ;
276+ result . should . have . property ( 'body' , 'SOME BODY' ) ;
277+ result . should . have . property ( 'encoding' , 'binary' ) ;
278+ result . should . have . property ( 'metadata' , null ) ;
276279 } ) ;
277280
278281 it ( 'should handle null input' , ( ) => {
279282 const result = request . transformResult ( null ) ;
280-
281- should ( result ) . eqls ( null ) ;
283+ ( result === null ) . should . be . true ;
282284 } ) ;
283285
284286 it ( 'should handle undefined input' , ( ) => {
285287 const result = request . transformResult ( undefined ) ;
286-
287- should ( result ) . eqls ( null ) ;
288+ ( result === null ) . should . be . true ;
288289 } ) ;
289290} ) ;
0 commit comments