Library for automatic setup of jest-cucumber tests based on .feature files and JavaScript step definitions.
Auto Jest Cucumber utilizes jest-cucumber to link step definitions to .feature files, making it easy to reutilize step definitions and facilitating the state management for each Scenario/Scenario Outline.
Even though jest-cucumber is very useful for linking tests running on Jest to Cucumber .feature files, the steps definition in pure jest-cucumber can be a little awkward. You have to basically remake the .feature file in JavaScript, defining every Scenario with all its steps. This is sub-optimal, as this information is already available in the .feature file and it gets hard to reuse steps in different Scenarios and .feature files. One workaround for that is to store the step definitions somewhere and import them when we configure jest-cucumber, but then this configuration would be a (completely pointless) second .feature file written in JavaScript. Auto Jest Cucumber can do this configuration automatically, parsing the .feature file, importing steps automatically from the steps definitions (in a similar manner to how Cucumber does it) and setting up the tests on Jest using jest-cucumber.
The following steps show how to setup a basic feature test using Auto Jest Cucumber with the default options.
It is possible to customize this behaviour, however that is not addressed here and is undocumented for now.
You can check the file src/features/self.js
for an example.
npm install auto-jest-cucumber --save-dev
"testPathIgnorePatterns": [
"<rootDir>(.*)/node_modules/(?!auto-jest-cucumber).*"
],
"moduleFileExtensions": [
"js",
"feature"
],
"haste": {
"providesModuleNodeModules": ["auto-jest-cucumber"]
}
# features/rocket-launching.feature
Feature: Rocket Launching
Scenario: Launching a SpaceX rocket
Given I am Elon Musk attempting to launch rocket "Falcon 9" into space
When I launch the rocket
Then the rocket should end up in space
And the booster(s) should land back on the launch pad
And nobody should doubt me ever again
// features/rocket-launching.steps.js
var Rocket = require('../rocket');
module.exports = [
[
/^I am Elon Musk attempting to launch rocket (.*) into space$/,
function (name) {
this.rocket = new Rocket(name);
}
],
[
'I launch the rocket',
function () {
this.rocket.launch();
}
],
[
'the rocket should end up in space',
function () {
expect(this.rocket.isInSpace).toBe(true);
}
],
[
'the booster(s) should land back on the launch pad',
function () {
expect(this.rocket.boostersLanded).toBe(true);
}
],
[
'nobody should doubt me ever again',
function () {
expect('people').not.toBe('haters');
}
]
];