Skip to content

Commit 5d14098

Browse files
committed
Use guard case instead of switch where possible in the Root tests
1 parent 1a8d8ea commit 5d14098

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

AuthenticatorTests/RootTests.swift

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ class RootTests: XCTestCase {
3434

3535
// Ensure there is no modal visible.
3636
let firstViewModel = root.viewModel(for: [], at: displayTime)
37-
switch firstViewModel.modal {
38-
case .none:
39-
// This is the expected case
40-
break
41-
default:
37+
guard case .none = firstViewModel.modal else {
4238
XCTFail("Expected .none, got \(firstViewModel.modal)")
39+
return
4340
}
4441

4542
// Show the backup info.
@@ -59,7 +56,7 @@ class RootTests: XCTestCase {
5956
case .info(let infoViewModel):
6057
XCTAssert(infoViewModel.title == "Backups")
6158
default:
62-
XCTFail("Expected .Info, got \(secondViewModel.modal)")
59+
XCTFail("Expected Backups .info, got \(secondViewModel.modal)")
6360
}
6461

6562
// Hide the backup info.
@@ -75,12 +72,9 @@ class RootTests: XCTestCase {
7572

7673
// Ensure the backup info modal no longer visible.
7774
let thirdViewModel = root.viewModel(for: [], at: displayTime)
78-
switch thirdViewModel.modal {
79-
case .none:
80-
// This is the expected case
81-
break
82-
default:
75+
guard case .none = thirdViewModel.modal else {
8376
XCTFail("Expected .none, got \(thirdViewModel.modal)")
77+
return
8478
}
8579
}
8680

@@ -89,12 +83,9 @@ class RootTests: XCTestCase {
8983

9084
// Ensure there is no modal visible.
9185
let firstViewModel = root.viewModel(for: [], at: displayTime)
92-
switch firstViewModel.modal {
93-
case .none:
94-
// This is the expected case
95-
break
96-
default:
86+
guard case .none = firstViewModel.modal else {
9787
XCTFail("Expected .none, got \(firstViewModel.modal)")
88+
return
9889
}
9990

10091
// Show the license info.
@@ -114,7 +105,7 @@ class RootTests: XCTestCase {
114105
case .info(let infoViewModel):
115106
XCTAssert(infoViewModel.title == "Acknowledgements")
116107
default:
117-
XCTFail("Expected .Info, got \(secondViewModel.modal)")
108+
XCTFail("Expected Acknowledgements .info, got \(secondViewModel.modal)")
118109
}
119110

120111
// Hide the license info.
@@ -130,12 +121,9 @@ class RootTests: XCTestCase {
130121

131122
// Ensure the license info modal no longer visible.
132123
let thirdViewModel = root.viewModel(for: [], at: displayTime)
133-
switch thirdViewModel.modal {
134-
case .none:
135-
// This is the expected case
136-
break
137-
default:
124+
guard case .none = thirdViewModel.modal else {
138125
XCTFail("Expected .none, got \(thirdViewModel.modal)")
126+
return
139127
}
140128
}
141129

@@ -156,11 +144,9 @@ class RootTests: XCTestCase {
156144
return
157145
}
158146

159-
switch effect {
160-
case .some(.openURL(let effectURL)):
161-
XCTAssertEqual(effectURL, url)
162-
default:
163-
XCTFail("Expected .none, got \(String(describing: effect))")
147+
guard case .some(.openURL(url)) = effect else {
148+
XCTFail("Expected .openURL(\(url)), got \(String(describing: effect))")
149+
return
164150
}
165151
}
166152

@@ -170,10 +156,7 @@ class RootTests: XCTestCase {
170156
let effect = root.update(event)
171157
// TODO: check that the component state hasn't changed
172158

173-
switch effect {
174-
case .some(.showErrorMessage("Failed to add token.")):
175-
break
176-
default:
159+
guard case .some(.showErrorMessage("Failed to add token.")) = effect else {
177160
XCTFail("Expected .showErrorMessage(\"Failed to add token.\"), got \(String(describing: effect))")
178161
return
179162
}

0 commit comments

Comments
 (0)