Skip to content

Commit bb18697

Browse files
committed
Allow chains to be returned from step definitions
1 parent d855007 commit bb18697

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

features/issues/713.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/713
2+
3+
Feature: returning chains
4+
Scenario: returning a chain
5+
Given a file named "cypress/integration/a.feature" with:
6+
"""
7+
Feature: a feature
8+
Scenario: a scenario
9+
Given a step
10+
"""
11+
And a file named "cypress/support/step_definitions/steps.js" with:
12+
"""
13+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
14+
Given("a step", () => cy.log("foo"))
15+
"""
16+
When I run cypress
17+
Then it passes

lib/create-tests.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,17 @@ function createPickle(
474474
return cy.wrap(start, { log: false });
475475
})
476476
.then((start) => {
477-
return cy
478-
.wrap(registry.runStepDefininition(this, text, argument), {
479-
log: false,
480-
})
481-
.then((result: any) => {
482-
return {
483-
start,
484-
result,
485-
};
486-
});
477+
const ensureChain = (value: any): Cypress.Chainable<any> =>
478+
Cypress.isCy(value) ? value : cy.wrap(value);
479+
480+
return ensureChain(
481+
registry.runStepDefininition(this, text, argument)
482+
).then((result: any) => {
483+
return {
484+
start,
485+
result,
486+
};
487+
});
487488
})
488489
.then(({ start, result }) => {
489490
const end = createTimestamp();

0 commit comments

Comments
 (0)