I'm using Nimble to create tests. When I try to test a class that is annotated as a main actor. The toEventually
method shows me the following warning:
Non-sendable type 'DispatchTimeInterval' exiting main actor-isolated context in call to non-isolated instance method 'toEventually(_:timeout:pollInterval:description:)' cannot cross actor boundary
I need to keep the main actor annotation on the test case. Here is an example:
import XCTest
import Nimble
@testable import ConcurrencyTest
@MainActor
class Test {
func testing(completion: @escaping () -> Void) {
Task {
sleep(1)
completion()
}
}
}
@MainActor
final class ConcurrencyTestTests: XCTestCase {
func testExample() async throws {
let test = Test()
var completionCalled = false
test.testing(completion: { completionCalled = true })
await expect(completionCalled).toEventually(beTrue()) // <-- warning
}
}
It is possible to remove the warning with extension DispatchTimeInterval: @unchecked Sendable {}
but seems hacky.
Can someone tell me if there is another method to remove the warning?
Thanks!