1. @cucumber/cucumber
The official JavaScript implementation of Cucumber.
@cucumber/cucumber
Package: @cucumber/cucumber
Created by: cucumber
Last modified: Thu, 25 Apr 2024 14:30:25 GMT
Version: 10.6.0
License: MIT
Downloads: 4,059,942
Repository: https://github.com/cucumber/cucumber-js

Install

npm install @cucumber/cucumber
yarn add @cucumber/cucumber


Cucumber

Automated tests in plain language, for Node.js

#StandWithUkraine
npm
build
coverage
backers
sponsors

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:

 npm install @cucumber/cucumber

Get Started

Let's take this example of something to test:

First, write your main code in src/index.js:

 class Greeter {
  sayHello() {
    return 'hello'
  }
}

module.exports = {
  Greeter
}

Then, write your feature in features/greeting.feature:

 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:

 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:

 npx cucumber-js

And see the output:

Terminal output showing a successful test run with 1 scenario and 2 steps, all passing

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

Support is available from the community if you need it.

Dependencies

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code