In MyModule, I have this enum:
enum MyError: ErrorType {
case failToSendMessage
case notAuthenticated
case noResponseReceived
}
In MyModuleTests:
import XCTest
@testable import MyModule
class MyModuleTests: XCTestCase {
func testNotAuthenticated() {
myClass.doSomething()
.subscribeError { error in
XCTAssertEqual(error, MyError.notAuthenticated)
}
}
}
doSomething
returns an Observable
.
Why do I get this error message:
Cannot invoke 'XCTAssertEqual' with an argument list ((ErrorType), MyError)
?
You should add an extension conforming Equatable for your MyError.
extension MyError: Equatable
{
static func == (lhs: MyError, rhs: MyError) -> Bool {
switch (lhs, rhs) {
case (.failToSendMessage, .failToSendMessage):
return true;
case (.notAuthenticated, .notAuthenticated):
return true;
case (.noResponseReceived, .noResponseReceived):
return true;
default:
return false;
}
}
}
And then, it's pretty simple to Assert your error.
if let error = result.error {
XCTAssertTrue(error == MyError.notAuthenticated,"API returns 403");
} else {
XCTFail("Response was not an error");
}
I.
As the error suggests , here you are trying to compare (ErrorType)
with MyError
using XCTAssertEqual
1.Check why you are getting error as (ErrorType)
instead of ErrorType
2.Try comparing after converting(Type cast) ErrorType
to MyError
error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With