Escaping callback closures execution order #51
-
In my use case, I want to access a variable that's assigned during
Note that this code works as expected, meaning I have |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The guarantee the library makes is that these will execute in the order defined in your Given The user is on home screen
Then Map is visible However, unless I maliciously manipulate your Gherkin (or you write such generic steps that accidental re-use causes issues) your code should be safe. One way you could choose to rewrite this so that it fails, but doesn't crash is: Given("^The user is on home screen$") { _, _ in
XCTAssertTrue(app.staticTexts["Welcome!"].exists)
}
var mapScreen: MapScreen?
When("^Map button is tapped$") { _, _ in
mapScreen = HomeScreen(app: app).tapMapButton()
}
Then("^Map is visible$") { _, _ in
let screen = try XCTUnwrap(mapScreen) // any errors thrown will get caught by XCTest
XCTAssertTrue(screen.verifyMapViewVisible())
} |
Beta Was this translation helpful? Give feedback.
The guarantee the library makes is that these will execute in the order defined in your
.feature
file. That means I could crash your tests by writing:However, unless I maliciously manipulate your Gherkin (or you write such generic steps that accidental re-use causes issues) your code should be safe.
One way you could choose to rewrite this so that it fails, but doesn't crash is: