XCTestExpectation just hangs

228 Views Asked by At

I have no idea what's going on. I'm using an expectation in my test and it will not timeout. I've removed so much of my test that now I'm just left with:

func testItem() {
    let expec = expectation(description: "expection")
    wait(for: [expec], timeout: 3.0)
}

And it won't fail. It just hangs. Does anyone know why this might be happening?

1

There are 1 best solutions below

0
On BEST ANSWER

If you are using XCTestCase.expectation(description:), which adds the returned XCTestExpectation to self.expectations, you should use waitForExpectations instead of wait(for:).

When using wait(for:) you should be creating your expectations using XCTestExpectation(description:).