Cucumber / Cucumber Js / Docs
World in Hooks
Background:
- Given a file named "
features/a.feature" with:gherkinFeature: some feature Scenario: some scenario Given a step - And a file named "
features/step_definitions/cucumber_steps.js" with:rubyconst {Given} = require('@cucumber/cucumber') Given(/^a step$/, function() {}) - And a file named "
features/support/world.js" with:rubyconst {setWorldConstructor} = require('@cucumber/cucumber') function WorldConstructor() { return { isWorld: function() { return true } } } setWorldConstructor(WorldConstructor)
Scenario: World is this in hooks
- Given a file named "
features/support/hooks.js" with:rubyconst {After, Before } = require('@cucumber/cucumber') Before(function() { if (!this.isWorld()) { throw Error("Expected this to be world") } }) After(function() { if (!this.isWorld()) { throw Error("Expected this to be world") } }) - When I run cucumber-js
- Then it passes
Scenario: World is this in BeforeStep hooks
- Given a file named "
features/support/hooks.js" with:rubyconst {BeforeStep } = require('@cucumber/cucumber') BeforeStep(function() { if (!this.isWorld()) { throw Error("Expected this to be world") } }) - When I run cucumber-js
- Then it passes
Scenario: World is this in AfterStep hooks
- Given a file named "
features/support/hooks.js" with:rubyconst {AfterStep } = require('@cucumber/cucumber') AfterStep(function() { if (!this.isWorld()) { throw Error("Expected this to be world") } }) - When I run cucumber-js
- Then it passes
Source: features/world_in_hooks.feature at commit 3ac6ecda, Cucumber Js (MIT license).