Skip to content

Commit 1ff2f95

Browse files
author
angu
committed
Fixed AsyncAssertThrowsError(_:_:_:) would not execute the error handler closure in case the evaluated expression throws an error.
1 parent 731bf8c commit 1ff2f95

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## HEAD
44

5+
* Fixed `AsyncAssertThrowsError(_:_:_:)` would not execute the error handler closure in case the evaluated expression throws an error.
6+
57
## 1.0.0
68

79
Initial release
@@ -25,5 +27,5 @@ Contains the following assert methods
2527
* `AsyncAssertNotIdentical(_:_:_:)`
2628
* `AsyncAssertNil(_:_:)`
2729
* `AsyncAssertNotNil(_:_:)`
28-
* `AsyncAssertThrowsError(_:_:)`
30+
* `AsyncAssertThrowsError(_:_:_:)`
2931
* `AsyncAssertNoThrow(_:_:)`

Sources/SwiftAsyncAssert/SwiftAsyncAssert.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ public func AsyncAssertNotNil(_ expression: @autoclosure () async throws -> Any?
201201
public func AsyncAssertThrowsError<T>(_ expression: @autoclosure () async throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line, _ errorHandler: (_ error: Error) -> Void = { _ in }) async {
202202
do {
203203
let _ = try await expression()
204-
XCTAssertThrowsError({}(), message(), file: file, line: line)
204+
XCTAssertThrowsError({}(), message(), file: file, line: line, errorHandler)
205205
} catch {
206-
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line)
206+
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line, errorHandler)
207207
}
208208
}
209209

Tests/SwiftAsyncAssertTests/SwiftAsyncAssertTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ final class SwiftAsyncAssertTests: XCTestCase {
107107
}
108108

109109
func test_should_pass_AsyncAssertThrows() async throws {
110+
var isErrorHandlerCalled = false
110111
await AsyncAssertThrowsError(try await throwingExpr { throw TestingError.systemFailedToWork }) { error in
111112
XCTAssertEqual(error as? TestingError, .systemFailedToWork)
113+
isErrorHandlerCalled = true
112114
}
115+
116+
XCTAssertTrue(isErrorHandlerCalled)
113117
}
114118

115119
func test_should_pass_AsyncAssertNotThrows() async throws {

0 commit comments

Comments
 (0)