Skip to content

Commit c0370d6

Browse files
committed
Assign window.testState at correct time
This fixes #836.
1 parent a19d687 commit c0370d6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
- Correctly assign `testState.pickleStep`, fixes [#836](https://github.com/badeball/cypress-cucumber-preprocessor/issues/836).
8+
59
## v13.0.1
610

711
- Support absolute paths in `stepDefinitions`, fixes [#832](https://github.com/badeball/cypress-cucumber-preprocessor/issues/832).

features/test_state.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ Feature: window.testState
5656
Feature: a feature name
5757
Scenario: a scenario name
5858
Given a step
59+
And another step
5960
"""
6061
And a file named "cypress/e2e/a.js" with:
6162
"""
6263
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
6364
Given("a step", function() {
6465
expect(testState.pickleStep.text).to.equal("a step");
6566
});
67+
Given("another step", function() {
68+
expect(testState.pickleStep.text).to.equal("another step");
69+
});
6670
"""
6771
When I run cypress
6872
Then it passes

lib/create-tests.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ function createPickle(
352352

353353
for (const step of steps) {
354354
if (step.hook) {
355-
delete window.testState.pickleStep;
356-
357355
const hook = step.hook;
358356

359357
cy.then(() => {
358+
delete window.testState.pickleStep;
359+
360360
Cypress.log({
361361
name: "step",
362362
displayName: hook.keyword,
@@ -402,8 +402,6 @@ function createPickle(
402402
remainingSteps.shift();
403403
});
404404
} else if (step.pickleStep) {
405-
window.testState.pickleStep = step.pickleStep;
406-
407405
const pickleStep = step.pickleStep;
408406

409407
const text = assertAndReturn(
@@ -422,6 +420,8 @@ function createPickle(
422420
);
423421

424422
cy.then(() => {
423+
window.testState.pickleStep = step.pickleStep;
424+
425425
Cypress.log({
426426
name: "step",
427427
displayName: assertAndReturn(

0 commit comments

Comments
 (0)