@@ -2,7 +2,7 @@ describe('Methods', function () {
22 describe ( 'defaults' , function ( ) {
33 it ( 'has defaults' , function ( ) {
44 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'] ) ;
66 expect ( defaults . method ) . to . equal ( 'GET' ) ;
77 expect ( defaults . baseUrl ) . to . equal ( '' ) ;
88 expect ( defaults . url ) . to . equal ( '' ) ;
@@ -12,6 +12,7 @@ describe('Methods', function () {
1212 expect ( defaults . responseTransformers ) . to . deep . equal ( [ yea . jsonResponseTransformer ] ) ;
1313 expect ( defaults . allowedStatusCode ) . to . deep . equal ( / ^ 2 [ 0 - 9 ] { 2 } $ / ) ;
1414 expect ( defaults . timeout ) . to . equal ( null ) ;
15+ expect ( defaults . prop ) . to . deep . equal ( [ ] ) ;
1516 expect ( defaults . polyfills ) . to . deep . equal ( { } ) ;
1617 } ) ;
1718 } ) ;
@@ -350,6 +351,43 @@ describe('Methods', function () {
350351 } ) ;
351352 } ) ;
352353
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+
353391 describe ( '.send' , function ( ) {
354392 it ( 'exists (see requests.spec.js for more tests)' , function ( ) {
355393 expect ( yea . send ) . to . be . ok ;
0 commit comments