@@ -2,7 +2,7 @@ describe('Methods', function () {
2
2
describe ( 'defaults' , function ( ) {
3
3
it ( 'has defaults' , function ( ) {
4
4
var defaults = yea . toObject ( ) ;
5
- expect ( defaults ) . to . have . keys ( [ 'method' , 'baseUrl' , 'url' , 'query' , 'body' , 'headers' , 'responseTransformers' , 'allowedStatusCode' , 'timeout' , 'polyfills' ] ) ;
5
+ expect ( defaults ) . to . have . keys ( [ 'method' , 'baseUrl' , 'url' , 'query' , 'body' , 'headers' , 'responseTransformers' , 'allowedStatusCode' , 'timeout' , 'prop' , ' polyfills'] ) ;
6
6
expect ( defaults . method ) . to . equal ( 'GET' ) ;
7
7
expect ( defaults . baseUrl ) . to . equal ( '' ) ;
8
8
expect ( defaults . url ) . to . equal ( '' ) ;
@@ -12,6 +12,7 @@ describe('Methods', function () {
12
12
expect ( defaults . responseTransformers ) . to . deep . equal ( [ yea . jsonResponseTransformer ] ) ;
13
13
expect ( defaults . allowedStatusCode ) . to . deep . equal ( / ^ 2 [ 0 - 9 ] { 2 } $ / ) ;
14
14
expect ( defaults . timeout ) . to . equal ( null ) ;
15
+ expect ( defaults . prop ) . to . deep . equal ( [ ] ) ;
15
16
expect ( defaults . polyfills ) . to . deep . equal ( { } ) ;
16
17
} ) ;
17
18
} ) ;
@@ -350,6 +351,43 @@ describe('Methods', function () {
350
351
} ) ;
351
352
} ) ;
352
353
354
+ describe ( '.prop' , function ( ) {
355
+ it ( 'sets prop' , function ( ) {
356
+ expect ( yea . prop ( null ) . toObject ( ) . prop ) . to . deep . equal ( [ ] ) ;
357
+ expect ( yea . prop ( '' ) . toObject ( ) . prop ) . to . deep . equal ( [ ] ) ;
358
+ expect ( yea . prop ( 'data.accounts[0]' ) . toObject ( ) . prop ) . to . deep . equal ( [ 'data' , 'accounts' , '0' ] ) ;
359
+ expect ( yea . prop ( [ 'data' , 'accounts' , '0' ] ) . toObject ( ) . prop ) . to . deep . equal ( [ 'data' , 'accounts' , '0' ] ) ;
360
+ } ) ;
361
+
362
+ it ( 'throws on unexpected type' , function ( ) {
363
+ expect ( function ( ) {
364
+ yea . prop ( { } ) ;
365
+ } ) . to . throw ( 'Expected a string (e.g. "data.items[0]") or an array for prop' ) ;
366
+
367
+ expect ( function ( ) {
368
+ yea . prop ( function ( ) { } ) ;
369
+ } ) . to . throw ( 'Expected a string (e.g. "data.items[0]") or an array for prop' ) ;
370
+
371
+ expect ( function ( ) {
372
+ yea . prop ( 123 ) ;
373
+ } ) . to . throw ( 'Expected a string (e.g. "data.items[0]") or an array for prop' ) ;
374
+ } ) ;
375
+
376
+ it ( 'leaves no reference to the array' , function ( ) {
377
+ var array = [ 'headers' , 'content-type' ] ;
378
+ var req = yea . prop ( array ) ;
379
+ expect ( req . toObject ( ) . prop ) . to . not . equal ( array ) ;
380
+ array . splice ( 0 , 1 ) ;
381
+ expect ( req . toObject ( ) . prop ) . to . deep . equal ( [ 'headers' , 'content-type' ] ) ;
382
+ } ) ;
383
+
384
+ it ( 'is immutable' , function ( ) {
385
+ var req = yea . prop ( 'data' ) ;
386
+ expect ( req ) . to . not . equal ( yea ) ;
387
+ expect ( req . constructor ) . to . equal ( yea . constructor ) ;
388
+ } ) ;
389
+ } ) ;
390
+
353
391
describe ( '.send' , function ( ) {
354
392
it ( 'exists (see requests.spec.js for more tests)' , function ( ) {
355
393
expect ( yea . send ) . to . be . ok ;
0 commit comments