@@ -185,12 +185,9 @@ class RootTests: XCTestCase {
185
185
var root = Root ( deviceCanScan: false )
186
186
187
187
// Ensure the initial view model has no modal.
188
- let firstViewModel = root. viewModel ( for: [ ] , at: displayTime)
189
- switch firstViewModel. modal {
190
- case . none:
191
- break
192
- default :
188
+ guard case . none = root. viewModel ( for: [ ] , at: displayTime) . modal else {
193
189
XCTFail ( " The initial view model should have no modal. " )
190
+ return
194
191
}
195
192
196
193
// Show the token entry form.
@@ -202,25 +199,19 @@ class RootTests: XCTestCase {
202
199
}
203
200
204
201
// Ensure the view model now has a modal entry form.
205
- let secondViewModel = root. viewModel ( for: [ ] , at: displayTime)
206
- switch secondViewModel. modal {
207
- case . entryForm:
208
- break
209
- default :
202
+ guard case . entryForm = root. viewModel ( for: [ ] , at: displayTime) . modal else {
210
203
XCTFail ( " The view model should have a modal entry form. " )
204
+ return
211
205
}
212
206
213
207
// Signal token entry success.
214
208
let effect = root. update ( . tokenFormSucceeded)
215
209
XCTAssertNil ( effect)
216
210
217
211
// Ensure the token entry form hides on success.
218
- let thirdViewModel = root. viewModel ( for: [ ] , at: displayTime)
219
- switch thirdViewModel. modal {
220
- case . none:
221
- break
222
- default :
212
+ guard case . none = root. viewModel ( for: [ ] , at: displayTime) . modal else {
223
213
XCTFail ( " The final view model should have no modal. " )
214
+ return
224
215
}
225
216
}
226
217
@@ -230,10 +221,7 @@ class RootTests: XCTestCase {
230
221
let effect = root. update ( event)
231
222
// TODO: check that the component state hasn't changed
232
223
233
- switch effect {
234
- case . some( . showErrorMessage( " Failed to save token. " ) ) :
235
- break
236
- default :
224
+ guard case . some( . showErrorMessage( " Failed to save token. " ) ) = effect else {
237
225
XCTFail ( " Expected .showErrorMessage( \" Failed to save token. \" ), got \( String ( describing: effect) ) " )
238
226
return
239
227
}
@@ -245,10 +233,7 @@ class RootTests: XCTestCase {
245
233
let effect = root. update ( event)
246
234
// TODO: check that the component state hasn't changed
247
235
248
- switch effect {
249
- case . some( . showErrorMessage( " Failed to update token. " ) ) :
250
- break
251
- default :
236
+ guard case . some( . showErrorMessage( " Failed to update token. " ) ) = effect else {
252
237
XCTFail ( " Expected .showErrorMessage( \" Failed to update token. \" ), got \( String ( describing: effect) ) " )
253
238
return
254
239
}
@@ -260,10 +245,7 @@ class RootTests: XCTestCase {
260
245
let effect = root. update ( event)
261
246
// TODO: check that the component state hasn't changed
262
247
263
- switch effect {
264
- case . some( . showErrorMessage( " Failed to move token. " ) ) :
265
- break
266
- default :
248
+ guard case . some( . showErrorMessage( " Failed to move token. " ) ) = effect else {
267
249
XCTFail ( " Expected .showErrorMessage( \" Failed to move token. \" ), got \( String ( describing: effect) ) " )
268
250
return
269
251
}
@@ -275,10 +257,7 @@ class RootTests: XCTestCase {
275
257
let effect = root. update ( event)
276
258
// TODO: check that the component state hasn't changed
277
259
278
- switch effect {
279
- case . some( . showErrorMessage( " Failed to delete token. " ) ) :
280
- break
281
- default :
260
+ guard case . some( . showErrorMessage( " Failed to delete token. " ) ) = effect else {
282
261
XCTFail ( " Expected .showErrorMessage( \" Failed to delete token. \" ), got \( String ( describing: effect) ) " )
283
262
return
284
263
}
0 commit comments