Unwrap the value, or throw an error.
// โญโโโญ๏ธโโโฎ func testUserToken() throws { let user = User() // if succeeds: get the value, if fails: throw an exception. let token = try XCTUnwrap(user.getToken()) // โญ๏ธ can throw XCTAssertEqual(token.count, 40) }
func XCTUnwrap<T>( _ expression: @autoclosure () throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, line: UInt = #line ) throws -> T
HwS โฉ How to check and unwrap optionals in tests using XCTUnwrap()
XCTest โฉ Nil and Non-Nil Assertions โฉ
XCTUnwrap(_:_:file:line:)
XCTAssertNotNil(::file:line:)
Last updated 3 years ago
Was this helpful?