Xcode unit test on simulator with MatrixSDK crashes on wait: NSDictionary key cannot be nil

Viewed 44

I have been working on refactoring my project from Cocoapods to SPM and one of the last hurdles is running the unit tests. The tests build fine with CMD+SHIFT+U and the project runs, but every unit test crashes at the end of the function when wait is called:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil'

An example of a test is this:

func testYork() throws {
    let exp = expectation(description: "Waiting for New York")
    var hasSearched = false
    cancellable = searchHandler.$foundSearchCompletions.sink { mapItems in
        print("Found items entered at once : \(mapItems.count)")
        guard hasSearched else {
            print("Hasn't searched yet")
            return
        }

        print("did search")
        XCTAssertTrue(!mapItems.isEmpty)
        exp.fulfill()
    }
    searchHandler.search(string: "New York")
    print("once search entered")
    hasSearched = true
    wait(for: [exp], timeout: 5)
}

These tests have been running fine before.


I've figured out it always crashes somewhere in the MatrixSDK, and it only crashes when I use the simulator. But it might be some kind of state problem in MatrixSDK that simply doesn't get triggered on my current install on my phone.

0 Answers
Related