@@ -35,38 +35,43 @@ describe('Axios VCR', function() {
35
35
36
36
it ( 'generates stubs for requests' , function ( done ) {
37
37
var path = './test/fixtures/posts.json'
38
- VCR . mountCassette ( path , function ( ) {
39
- axios . get ( posts ) . then ( function ( response ) {
40
- getFixture ( path , response . config ) . then ( function ( fixture ) {
41
- assert . deepEqual ( fixture . originalResponseData . data , response . data )
42
- done ( )
43
- } )
38
+ VCR . mountCassette ( path )
39
+
40
+ axios . get ( posts ) . then ( function ( response ) {
41
+ getFixture ( path , response . config ) . then ( function ( fixture ) {
42
+ assert . deepEqual ( fixture . originalResponseData . data , response . data )
43
+ done ( )
44
+ VCR . ejectCassette ( path )
44
45
} )
45
46
} )
46
47
} )
47
48
48
49
it ( 'works with nested folders' , function ( done ) {
49
50
var cassettePath = './test/fixtures/nested/posts.json'
50
- VCR . mountCassette ( cassettePath , function ( ) {
51
- axios . get ( posts ) . then ( function ( response ) {
52
- getFixture ( cassettePath , response . config ) . then ( function ( fixture ) {
53
- assert . deepEqual ( fixture . originalResponseData . data , response . data )
54
- done ( )
55
- } )
56
- } ) . catch ( function ( err ) { console . log ( err ) } )
57
- } )
51
+ VCR . mountCassette ( cassettePath )
52
+
53
+ axios . get ( posts ) . then ( function ( response ) {
54
+ getFixture ( cassettePath , response . config ) . then ( function ( fixture ) {
55
+ assert . deepEqual ( fixture . originalResponseData . data , response . data )
56
+ done ( )
57
+
58
+ VCR . ejectCassette ( cassettePath )
59
+ } )
60
+ } ) . catch ( function ( err ) { console . log ( err ) } )
58
61
} )
59
62
60
63
it ( 'stores headers and status' , function ( done ) {
61
64
var cassettePath = './test/fixtures/posts.json'
62
- VCR . mountCassette ( cassettePath , function ( ) {
63
- axios . get ( posts ) . then ( function ( response ) {
64
- getFixture ( cassettePath , response . config ) . then ( function ( fixture ) {
65
- assert . deepEqual ( fixture . originalResponseData . headers , response . headers )
66
- assert . equal ( fixture . originalResponseData . status , response . status )
67
- assert . equal ( fixture . originalResponseData . statusText , response . statusText )
68
- done ( )
69
- } )
65
+ VCR . mountCassette ( cassettePath )
66
+
67
+ axios . get ( posts ) . then ( function ( response ) {
68
+ getFixture ( cassettePath , response . config ) . then ( function ( fixture ) {
69
+ assert . deepEqual ( fixture . originalResponseData . headers , response . headers )
70
+ assert . equal ( fixture . originalResponseData . status , response . status )
71
+ assert . equal ( fixture . originalResponseData . statusText , response . statusText )
72
+ done ( )
73
+
74
+ VCR . ejectCassette ( cassettePath )
70
75
} )
71
76
} )
72
77
} )
@@ -84,14 +89,15 @@ describe('Axios VCR', function() {
84
89
assert ( fileExists ( path ) )
85
90
86
91
var url = 'http://something.com/unexisting'
92
+ VCR . mountCassette ( path )
87
93
88
- VCR . mountCassette ( path , function ( ) {
89
- axios . get ( url ) . then ( function ( res ) {
90
- getFixture ( path , res . config ) . then ( function ( fixture ) {
91
- assert . deepEqual ( fixture . originalResponseData , _ . omit ( res , 'fixture' ) )
92
- done ( )
93
- } ) . catch ( err => { console . log ( err ) ; done ( ) } )
94
- } )
94
+ axios . get ( url ) . then ( function ( res ) {
95
+ getFixture ( path , res . config ) . then ( function ( fixture ) {
96
+ assert . deepEqual ( fixture . originalResponseData , _ . omit ( res , ' fixture' ) )
97
+ done ( )
98
+
99
+ VCR . ejectCassette ( path )
100
+ } ) . catch ( err => { console . log ( err ) ; done ( ) } )
95
101
} )
96
102
} )
97
103
@@ -103,13 +109,14 @@ describe('Axios VCR', function() {
103
109
} catch ( e ) { }
104
110
105
111
assert ( ! fileExists ( path ) )
112
+ VCR . mountCassette ( path )
106
113
107
- VCR . mountCassette ( path , function ( ) {
108
- axios . get ( posts ) . then ( function ( response ) {
109
- assert . equal ( 200 , response . status )
110
- fs . unlinkSync ( path )
111
- done ( )
112
- } )
114
+ axios . get ( posts ) . then ( function ( response ) {
115
+ assert . equal ( 200 , response . status )
116
+ fs . unlinkSync ( path )
117
+ done ( )
118
+
119
+ VCR . ejectCassette ( path )
113
120
} )
114
121
} )
115
122
} )
@@ -126,22 +133,24 @@ describe('Axios VCR', function() {
126
133
it ( 'stores multiple requests in the same cassette' , function ( done ) {
127
134
var path = './test/fixtures/multiple.json'
128
135
129
- VCR . mountCassette ( path , function ( ) {
130
- var usersPromise = axios . get ( usersUrl )
131
- var todosPromise = axios . get ( todosUrl )
136
+ VCR . mountCassette ( path )
137
+
138
+ var usersPromise = axios . get ( usersUrl )
139
+ var todosPromise = axios . get ( todosUrl )
132
140
133
- Promise . all ( [ usersPromise , todosPromise ] ) . then ( function ( responses ) {
134
- var usersResponse = responses [ 0 ]
135
- var todosResponse = responses [ 1 ]
141
+ Promise . all ( [ usersPromise , todosPromise ] ) . then ( function ( responses ) {
142
+ var usersResponse = responses [ 0 ]
143
+ var todosResponse = responses [ 1 ]
136
144
137
- var usersResponsePromise = getFixture ( path , usersResponse . config )
138
- var todosResponsePromise = getFixture ( path , todosResponse . config )
145
+ var usersResponsePromise = getFixture ( path , usersResponse . config )
146
+ var todosResponsePromise = getFixture ( path , todosResponse . config )
147
+
148
+ Promise . all ( [ usersResponsePromise , todosResponsePromise ] ) . then ( function ( fixtures ) {
149
+ assert . deepEqual ( fixtures [ 0 ] . originalResponseData . data , usersResponse . data )
150
+ assert . deepEqual ( fixtures [ 1 ] . originalResponseData . data , todosResponse . data )
151
+ done ( )
139
152
140
- Promise . all ( [ usersResponsePromise , todosResponsePromise ] ) . then ( function ( fixtures ) {
141
- assert . deepEqual ( fixtures [ 0 ] . originalResponseData . data , usersResponse . data )
142
- assert . deepEqual ( fixtures [ 1 ] . originalResponseData . data , todosResponse . data )
143
- done ( )
144
- } )
153
+ VCR . ejectCassette ( path )
145
154
} )
146
155
} )
147
156
} )
0 commit comments