Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke 'XCTAssertEqual' with an argument list ((ErrorType), XMPPError)

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) ?

like image 654
Fredric Sanjaya Avatar asked Oct 11 '16 07:10

Fredric Sanjaya


2 Answers

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.

like image 193
isanjosgon Avatar answered Oct 01 '22 08:10

isanjosgon


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.

like image 33
user3608500 Avatar answered Oct 01 '22 08:10

user3608500