Cucumber.js
Cucumber for JavaScript
README
Cucumber
Automated tests in plain language, for Node.js
Cucumber is a tool for running automated tests written in plain language. Because they're
written in plain language, they can be read by anyone on your team. Because they can be
read by anyone, you can use them to help improve communication, collaboration and trust on
your team.
This is the JavaScript implementation of Cucumber. It runs on maintained versions of Node.js. You can quickly try it via CodeSandbox, or read on to get started locally in a couple of minutes.
Looking to contribute? Read our code of conduct first, then check the contributing guide to get up and running.
Install
Cucumber is available on npm:
- ``` sh
- $ npm install @cucumber/cucumber
- ```
Get Started
Let's take this example of something to test:
- ``` js
- class Greeter {
- sayHello() {
- return 'hello'
- }
- }
- ```
First, write your feature in features/greeting.feature:
- ```gherkin
- Feature: Greeting
- Scenario: Say hello
- When the greeter says hello
- Then I should have heard "hello"
- ```
Next, implement your steps in features/support/steps.js:
- ``` js
- const assert = require('assert')
- const { When, Then } = require('@cucumber/cucumber')
- const { Greeter } = require('../../src')
- When('the greeter says hello', function () {
- this.whatIHeard = new Greeter().sayHello()
- });
- Then('I should have heard {string}', function (expectedResponse) {
- assert.equal(this.whatIHeard, expectedResponse)
- });
- ```
Finally, run Cucumber:
- ``` sh
- $ npx cucumber-js
- ```
And see the output:
If you learn best by example, we have a repo with several example projects, that might help you get going.
Documentation
The following documentation is for main, which might contain some unreleased features. See documentation for older versions if you need it.
Support Code
Guides
Support
Support is available from the community if you need it.