cucumber/cucumber-js — Issue #38: Supporting step definitions assertions in callbacks
Author: kareemk
Created: 2011-12-14 23:54:37+00:00
State: open

Given step definitions currently rely on failures in step definitions to be synchronous:

support_code/step_definitions.js:19

```javascript
try {
code.apply(world, parameters);
} catch (exception) {
if (exception)
Cucumber.Debug.warn(exception.stack || exception, 'exception inside feature', 3);
var stepResult;
if (exception instanceof Cucumber.Runtime.PendingStepException)
stepResult = Cucumber.Runtime.PendingStepResult()
else
stepResult = Cucumber.Runtime.FailedStepResult(exception);
callback(stepResult);
}
```

It's not possible to handle assertions that need to be made in callbacks, which is the case when using phantomjs as the bridge is asynchronous. So:

```javascript
this.browser.evaluate(function(){ "$('#id').length"}, function(result) {
result.should.not.eql(0)
});
```

Won't fail the scenario if the assertion fails.

Seems like the best approach is to support firing an error event in the case of doing assertions in callbacks (as well as directly throwing exceptions in step definitions. Thoughts? Happy to work on this once we flush out the ideal approach.