Skip to content

Commit 8f78f36

Browse files
authored
Merge pull request #37 from raphaelguye/feature/throwable-error-test
Adding a test case for the trowable error
2 parents 492bed5 + 7ed3a3e commit 8f78f36

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Examples/Tests/ViewModelTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,25 @@ final class ViewModelTests: XCTestCase {
3939
XCTAssertEqual(serviceSpy.fetchConfigArgCallsCount, 2)
4040
XCTAssertEqual(serviceSpy.fetchConfigArgReceivedInvocations, [1, 2])
4141
}
42+
43+
func testThrowableError() async throws {
44+
serviceSpy.fetchConfigArgThrowableError = CustomError.expected
45+
46+
do {
47+
try await sut.saveConfig()
48+
XCTFail("An error should have been thrown by the sut")
49+
} catch CustomError.expected {
50+
XCTAssertEqual(serviceSpy.fetchConfigArgCallsCount, 1)
51+
XCTAssertEqual(serviceSpy.fetchConfigArgReceivedInvocations, [1])
52+
XCTAssertTrue(sut.config.isEmpty)
53+
} catch {
54+
XCTFail("Unexpected error catched")
55+
}
56+
}
57+
}
58+
59+
extension ViewModelTests {
60+
enum CustomError: Error {
61+
case expected
62+
}
4263
}

0 commit comments

Comments
 (0)