@@ -101,8 +101,8 @@ describe('MockAdapter basics', function() {
101
101
it ( 'accepts a callback that returns an axios request' , function ( ) {
102
102
mock
103
103
. onGet ( '/bar' )
104
- . reply ( 200 , { foo : 'bar' } )
105
- . onGet ( '/foo' )
104
+ . reply ( 200 , { foo : 'bar' } ) ;
105
+ mock . onGet ( '/foo' )
106
106
. reply ( function ( ) {
107
107
return instance . get ( '/bar' ) ;
108
108
} ) ;
@@ -216,6 +216,18 @@ describe('MockAdapter basics', function() {
216
216
} ) ;
217
217
} ) ;
218
218
219
+ it ( 'allow removing mock handler' , function ( ) {
220
+ const handler = mock . onGet ( '/' ) . reply ( 200 ) ;
221
+ return instance . get ( '/' ) . then ( function ( response ) {
222
+ expect ( response . status ) . to . equal ( 200 ) ;
223
+ mock . removeHandler ( handler ) ;
224
+ return instance . get ( '/' ) ;
225
+ } ) . catch ( function ( error ) {
226
+ expect ( error . response . status ) . to . equal ( 404 ) ;
227
+ expect ( handler . called ) . to . equal ( 1 ) ;
228
+ } ) ;
229
+ } ) ;
230
+
219
231
it ( 'matches when parameters were not expected' , function ( ) {
220
232
mock . onGet ( '/withParams' ) . reply ( 200 ) ;
221
233
return instance
@@ -466,10 +478,10 @@ describe('MockAdapter basics', function() {
466
478
it ( 'can chain calls to add mock handlers' , function ( ) {
467
479
mock
468
480
. onGet ( '/foo' )
469
- . reply ( 200 )
470
- . onAny ( '/bar' )
481
+ . reply ( 200 ) ;
482
+ mock . onAny ( '/bar' )
471
483
. reply ( 404 )
472
- . onPost ( '/baz' )
484
+ mock . onPost ( '/baz' )
473
485
. reply ( 500 ) ;
474
486
475
487
expect ( mock . handlers [ 'get' ] . length ) . to . equal ( 2 ) ;
@@ -510,10 +522,9 @@ describe('MockAdapter basics', function() {
510
522
} ) ;
511
523
512
524
it ( 'maps empty GET path to any path' , function ( ) {
513
- mock
514
- . onGet ( '/foo' )
515
- . reply ( 200 , 'foo' )
516
- . onGet ( )
525
+ mock . onGet ( '/foo' )
526
+ . reply ( 200 , 'foo' ) ;
527
+ mock . onGet ( )
517
528
. reply ( 200 , 'bar' ) ;
518
529
519
530
return Promise . all ( [
@@ -636,14 +647,13 @@ describe('MockAdapter basics', function() {
636
647
} ) ;
637
648
638
649
it ( 'supports chaining on same path with different params' , function ( ) {
639
- mock
640
- . onGet ( '/users' , { params : { searchText : 'John' } } )
641
- . reply ( 200 , { id : 1 } )
642
- . onGet ( '/users' , { params : { searchText : 'James' } } )
643
- . reply ( 200 , { id : 2 } )
644
- . onGet ( '/users' , { params : { searchText : 'Jake' } } )
645
- . reply ( 200 , { id : 3 } )
646
- . onGet ( '/users' , { params : { searchText : 'Jackie' } } )
650
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
651
+ . reply ( 200 , { id : 1 } ) ;
652
+ mock . onGet ( '/users' , { params : { searchText : 'James' } } )
653
+ . reply ( 200 , { id : 2 } ) ;
654
+ mock . onGet ( '/users' , { params : { searchText : 'Jake' } } )
655
+ . reply ( 200 , { id : 3 } ) ;
656
+ mock . onGet ( '/users' , { params : { searchText : 'Jackie' } } )
647
657
. reply ( 200 , { id : 4 } ) ;
648
658
649
659
return instance
@@ -739,10 +749,9 @@ describe('MockAdapter basics', function() {
739
749
} ) ;
740
750
741
751
it ( 'allows overwriting mocks with parameters' , function ( ) {
742
- mock
743
- . onGet ( '/users' , { params : { searchText : 'John' } } )
744
- . reply ( 500 )
745
- . onGet ( '/users' , { params : { searchText : 'John' } } )
752
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
753
+ . reply ( 500 ) ;
754
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
746
755
. reply ( 200 , { id : 1 } ) ;
747
756
748
757
return instance
0 commit comments