@@ -9,20 +9,22 @@ function expectCodemodResult(src, expected) {
9
9
}
10
10
11
11
describe ( 'codemods operating on options' , ( ) => {
12
+ const overwriteTrueErrorString =
13
+ 'throw new Error("`overwriteRoutes: true` option is deprecated. Use the `modifyRoute()` method instead")' ;
12
14
[ 'overwriteRoutes' , 'warnOnFallback' , 'sendAsJson' ] . forEach ( ( optionName ) => {
13
15
describe ( optionName , ( ) => {
14
16
it ( 'Removes as global option when setting directly as property' , ( ) => {
15
- expectCodemodResult ( `fetchMock.config.${ optionName } = true ` , '' ) ;
17
+ expectCodemodResult ( `fetchMock.config.${ optionName } = false ` , '' ) ;
16
18
} ) ;
17
19
it ( 'Removes as global option when using Object.assign' , ( ) => {
18
20
expectCodemodResult (
19
- `Object.assign(fetchMock.config, {${ optionName } : true })` ,
21
+ `Object.assign(fetchMock.config, {${ optionName } : false })` ,
20
22
'' ,
21
23
) ;
22
24
} ) ;
23
25
it ( 'Removes as global option when using Object.assign alongside other options' , ( ) => {
24
26
expectCodemodResult (
25
- `Object.assign(fetchMock.config, {${ optionName } : true , other: 'value'})` ,
27
+ `Object.assign(fetchMock.config, {${ optionName } : false , other: 'value'})` ,
26
28
`Object.assign(fetchMock.config, {
27
29
other: 'value'
28
30
})` ,
@@ -60,7 +62,7 @@ describe('codemods operating on options', () => {
60
62
if ( methodName === 'getAnyOnce' ) {
61
63
it ( `Removes as option on third parameter of ${ methodName } ()` , ( ) => {
62
64
expectCodemodResult (
63
- `fetchMock.getAnyOnce(200, {name: 'rio', ${ optionName } : true })` ,
65
+ `fetchMock.getAnyOnce(200, {name: 'rio', ${ optionName } : false })` ,
64
66
`fetchMock.getOnce("*", 200, {
65
67
name: 'rio'
66
68
})` ,
@@ -69,14 +71,14 @@ describe('codemods operating on options', () => {
69
71
70
72
it ( `Removes third parameter of ${ methodName } () if no other options remain` , ( ) => {
71
73
expectCodemodResult (
72
- `fetchMock.getAnyOnce(200, {${ optionName } : true })` ,
74
+ `fetchMock.getAnyOnce(200, {${ optionName } : false })` ,
73
75
`fetchMock.getOnce("*", 200)` ,
74
76
) ;
75
77
} ) ;
76
78
} else if ( / a n y / . test ( methodName ) ) {
77
79
it ( `Removes as option on third parameter of ${ methodName } ()` , ( ) => {
78
80
expectCodemodResult (
79
- `fetchMock.${ methodName } (200, {name: 'rio', ${ optionName } : true })` ,
81
+ `fetchMock.${ methodName } (200, {name: 'rio', ${ optionName } : false })` ,
80
82
`fetchMock.${ newMethodName } (200, {
81
83
name: 'rio'
82
84
})` ,
@@ -85,14 +87,14 @@ describe('codemods operating on options', () => {
85
87
86
88
it ( `Removes third parameter of ${ methodName } () if no other options remain` , ( ) => {
87
89
expectCodemodResult (
88
- `fetchMock.${ methodName } (200, {${ optionName } : true })` ,
90
+ `fetchMock.${ methodName } (200, {${ optionName } : false })` ,
89
91
`fetchMock.${ newMethodName } (200)` ,
90
92
) ;
91
93
} ) ;
92
94
} else {
93
95
it ( `Removes as option on first parameter of ${ methodName } ()` , ( ) => {
94
96
expectCodemodResult (
95
- `fetchMock.${ methodName } ({url: '*', response: 200, ${ optionName } : true })` ,
97
+ `fetchMock.${ methodName } ({url: '*', response: 200, ${ optionName } : false })` ,
96
98
`fetchMock.${ newMethodName } ({
97
99
url: '*',
98
100
response: 200
@@ -101,7 +103,7 @@ describe('codemods operating on options', () => {
101
103
} ) ;
102
104
it ( `Removes as option on third parameter of ${ methodName } ()` , ( ) => {
103
105
expectCodemodResult (
104
- `fetchMock.${ methodName } ('*', 200, {name: 'rio', ${ optionName } : true })` ,
106
+ `fetchMock.${ methodName } ('*', 200, {name: 'rio', ${ optionName } : false })` ,
105
107
`fetchMock.${ newMethodName } ('*', 200, {
106
108
name: 'rio'
107
109
})` ,
@@ -110,24 +112,53 @@ describe('codemods operating on options', () => {
110
112
111
113
it ( `Removes third parameter of ${ methodName } () if no other options remain` , ( ) => {
112
114
expectCodemodResult (
113
- `fetchMock.${ methodName } ('*', 200, {${ optionName } : true })` ,
115
+ `fetchMock.${ methodName } ('*', 200, {${ optionName } : false })` ,
114
116
`fetchMock.${ newMethodName } ('*', 200)` ,
115
117
) ;
116
118
} ) ;
119
+
120
+ if ( optionName === 'overwriteRoutes' ) {
121
+ describe ( 'overwriteRoutes: true' , ( ) => {
122
+ it ( `Removes as option on first parameter of ${ methodName } ()` , ( ) => {
123
+ expectCodemodResult (
124
+ `fetchMock.${ methodName } ({url: '*', response: 200, ${ optionName } : true})` ,
125
+ `fetchMock.${ newMethodName } ({
126
+ url: '*',
127
+ response: 200
128
+ })${ overwriteTrueErrorString } ` ,
129
+ ) ;
130
+ } ) ;
131
+ it ( `Removes as option on third parameter of ${ methodName } ()` , ( ) => {
132
+ expectCodemodResult (
133
+ `fetchMock.${ methodName } ('*', 200, {name: 'rio', ${ optionName } : true})` ,
134
+ `fetchMock.${ newMethodName } ('*', 200, {
135
+ name: 'rio'
136
+ })${ overwriteTrueErrorString } ` ,
137
+ ) ;
138
+ } ) ;
139
+
140
+ it ( `Removes third parameter of ${ methodName } () if no other options remain` , ( ) => {
141
+ expectCodemodResult (
142
+ `fetchMock.${ methodName } ('*', 200, {${ optionName } : true})` ,
143
+ `fetchMock.${ newMethodName } ('*', 200)${ overwriteTrueErrorString } ` ,
144
+ ) ;
145
+ } ) ;
146
+ } ) ;
147
+ }
117
148
}
118
149
} ) ;
119
150
} ) ;
120
151
} ) ;
121
152
describe ( 'acting on combinations of the 3 options together' , ( ) => {
122
153
it ( 'Removes as global option when using Object.assign' , ( ) => {
123
154
expectCodemodResult (
124
- `Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: true })` ,
155
+ `Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: false })` ,
125
156
'' ,
126
157
) ;
127
158
} ) ;
128
159
it ( 'Removes as global option when using Object.assign alongside other options' , ( ) => {
129
160
expectCodemodResult (
130
- `Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: true , other: 'value'})` ,
161
+ `Object.assign(fetchMock.config, {sendAsJson: true, overwriteRoutes: false , other: 'value'})` ,
131
162
`Object.assign(fetchMock.config, {
132
163
other: 'value'
133
164
})` ,
@@ -136,7 +167,7 @@ describe('codemods operating on options', () => {
136
167
137
168
it ( `Removes as option on third parameter of getAnyOnce()` , ( ) => {
138
169
expectCodemodResult (
139
- `fetchMock.getAnyOnce(200, {name: 'rio', sendAsJson: true, overwriteRoutes: true })` ,
170
+ `fetchMock.getAnyOnce(200, {name: 'rio', sendAsJson: true, overwriteRoutes: false })` ,
140
171
`fetchMock.getOnce("*", 200, {
141
172
name: 'rio'
142
173
})` ,
@@ -145,13 +176,13 @@ describe('codemods operating on options', () => {
145
176
146
177
it ( `Removes third parameter of getAnyOnce() if no other options remain` , ( ) => {
147
178
expectCodemodResult (
148
- `fetchMock.getAnyOnce(200, {sendAsJson: true, overwriteRoutes: true })` ,
179
+ `fetchMock.getAnyOnce(200, {sendAsJson: true, overwriteRoutes: false })` ,
149
180
`fetchMock.getOnce("*", 200)` ,
150
181
) ;
151
182
} ) ;
152
183
it ( `Removes as option on third parameter of any()` , ( ) => {
153
184
expectCodemodResult (
154
- `fetchMock.any(200, {name: 'rio', sendAsJson: true, overwriteRoutes: true })` ,
185
+ `fetchMock.any(200, {name: 'rio', sendAsJson: true, overwriteRoutes: false })` ,
155
186
`fetchMock.any(200, {
156
187
name: 'rio'
157
188
})` ,
@@ -160,13 +191,13 @@ describe('codemods operating on options', () => {
160
191
161
192
it ( `Removes third parameter of any() if no other options remain` , ( ) => {
162
193
expectCodemodResult (
163
- `fetchMock.any(200, {sendAsJson: true, overwriteRoutes: true })` ,
194
+ `fetchMock.any(200, {sendAsJson: true, overwriteRoutes: false })` ,
164
195
`fetchMock.any(200)` ,
165
196
) ;
166
197
} ) ;
167
198
it ( `Removes as option on first parameter of get()` , ( ) => {
168
199
expectCodemodResult (
169
- `fetchMock.get({url: '*', response: 200, sendAsJson: true, overwriteRoutes: true })` ,
200
+ `fetchMock.get({url: '*', response: 200, sendAsJson: true, overwriteRoutes: false })` ,
170
201
`fetchMock.get({
171
202
url: '*',
172
203
response: 200
@@ -175,7 +206,7 @@ describe('codemods operating on options', () => {
175
206
} ) ;
176
207
it ( `Removes as option on third parameter of get()` , ( ) => {
177
208
expectCodemodResult (
178
- `fetchMock.get('*', 200, {name: 'rio', sendAsJson: true, overwriteRoutes: true })` ,
209
+ `fetchMock.get('*', 200, {name: 'rio', sendAsJson: true, overwriteRoutes: false })` ,
179
210
`fetchMock.get('*', 200, {
180
211
name: 'rio'
181
212
})` ,
@@ -184,7 +215,7 @@ describe('codemods operating on options', () => {
184
215
185
216
it ( `Removes third parameter of get() if no other options remain` , ( ) => {
186
217
expectCodemodResult (
187
- `fetchMock.get('*', 200, {sendAsJson: true, overwriteRoutes: true })` ,
218
+ `fetchMock.get('*', 200, {sendAsJson: true, overwriteRoutes: false })` ,
188
219
`fetchMock.get('*', 200)` ,
189
220
) ;
190
221
} ) ;
0 commit comments