@@ -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
@@ -510,10 +522,10 @@ describe('MockAdapter basics', function() {
510
522
it ( 'can chain calls to add mock handlers' , function ( ) {
511
523
mock
512
524
. onGet ( '/foo' )
513
- . reply ( 200 )
514
- . onAny ( '/bar' )
515
- . reply ( 404 )
516
- . onPost ( '/baz' )
525
+ . reply ( 200 ) ;
526
+ mock . onAny ( '/bar' )
527
+ . reply ( 404 ) ;
528
+ mock . onPost ( '/baz' )
517
529
. reply ( 500 ) ;
518
530
519
531
expect ( mock . handlers [ 'get' ] . length ) . to . equal ( 2 ) ;
@@ -554,10 +566,9 @@ describe('MockAdapter basics', function() {
554
566
} ) ;
555
567
556
568
it ( 'maps empty GET path to any path' , function ( ) {
557
- mock
558
- . onGet ( '/foo' )
559
- . reply ( 200 , 'foo' )
560
- . onGet ( )
569
+ mock . onGet ( '/foo' )
570
+ . reply ( 200 , 'foo' ) ;
571
+ mock . onGet ( )
561
572
. reply ( 200 , 'bar' ) ;
562
573
563
574
return Promise . all ( [
@@ -680,14 +691,13 @@ describe('MockAdapter basics', function() {
680
691
} ) ;
681
692
682
693
it ( 'supports chaining on same path with different params' , function ( ) {
683
- mock
684
- . onGet ( '/users' , { params : { searchText : 'John' } } )
685
- . reply ( 200 , { id : 1 } )
686
- . onGet ( '/users' , { params : { searchText : 'James' } } )
687
- . reply ( 200 , { id : 2 } )
688
- . onGet ( '/users' , { params : { searchText : 'Jake' } } )
689
- . reply ( 200 , { id : 3 } )
690
- . onGet ( '/users' , { params : { searchText : 'Jackie' } } )
694
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
695
+ . reply ( 200 , { id : 1 } ) ;
696
+ mock . onGet ( '/users' , { params : { searchText : 'James' } } )
697
+ . reply ( 200 , { id : 2 } ) ;
698
+ mock . onGet ( '/users' , { params : { searchText : 'Jake' } } )
699
+ . reply ( 200 , { id : 3 } ) ;
700
+ mock . onGet ( '/users' , { params : { searchText : 'Jackie' } } )
691
701
. reply ( 200 , { id : 4 } ) ;
692
702
693
703
return instance
@@ -783,10 +793,9 @@ describe('MockAdapter basics', function() {
783
793
} ) ;
784
794
785
795
it ( 'allows overwriting mocks with parameters' , function ( ) {
786
- mock
787
- . onGet ( '/users' , { params : { searchText : 'John' } } )
788
- . reply ( 500 )
789
- . onGet ( '/users' , { params : { searchText : 'John' } } )
796
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
797
+ . reply ( 500 ) ;
798
+ mock . onGet ( '/users' , { params : { searchText : 'John' } } )
790
799
. reply ( 200 , { id : 1 } ) ;
791
800
792
801
return instance
0 commit comments