Skip to content

Instantly share code, notes, and snippets.

@andreacipriani
Created April 6, 2020 17:35
Show Gist options
  • Save andreacipriani/bc0b2e0e0736d339b29ab70de84fca35 to your computer and use it in GitHub Desktop.
Save andreacipriani/bc0b2e0e0736d339b29ab70de84fca35 to your computer and use it in GitHub Desktop.
Show the problem of testing an async function in Tuist
class Subject {
let dependency: Dependency
func doSomethingAsync() {
DispatchQueue.main.async {
dependency.doSomething()
}
}
}
final class SubjectTests: XCTTestCase {
func testDoSomethingAsync_callsDependency() {
let fakeDependency = FakeDependency()
let subject = Subject(dependency: fakeDependency)
subject.doSomethingAsync()
XCTAssertEqual(fakeDependency.doSomethingCallCount, 1) // It will fail because the implementation is async
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment