Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-cucumber

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-cucumber

Execute Gherkin scenarios in Jest

  • 4.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
271K
decreased by-12.04%
Maintainers
1
Weekly downloads
 
Created

What is jest-cucumber?

jest-cucumber is an npm package that allows you to write BDD (Behavior-Driven Development) tests using Gherkin syntax and run them with Jest. It bridges the gap between business stakeholders and developers by enabling the creation of human-readable test scenarios.

What are jest-cucumber's main functionalities?

Define Feature Files

You can define your test scenarios in Gherkin syntax, which is a human-readable format. This makes it easier for non-developers to understand the test cases.

Feature: Addition
  Scenario: Add two numbers
    Given I have entered 50 into the calculator
    And I have entered 70 into the calculator
    When I press add
    Then the result should be 120 on the screen

Step Definitions

You can define step definitions in JavaScript to map the Gherkin steps to actual test code. This allows you to implement the logic for each step in your test scenarios.

const { defineFeature, loadFeature } = require('jest-cucumber');
const feature = loadFeature('./features/addition.feature');

defineFeature(feature, test => {
  test('Add two numbers', ({ given, when, then }) => {
    let calculator;

    given('I have entered 50 into the calculator', () => {
      calculator = new Calculator();
      calculator.enter(50);
    });

    given('I have entered 70 into the calculator', () => {
      calculator.enter(70);
    });

    when('I press add', () => {
      calculator.add();
    });

    then('the result should be 120 on the screen', () => {
      expect(calculator.result).toBe(120);
    });
  });
});

Integration with Jest

jest-cucumber integrates seamlessly with Jest, allowing you to run your BDD tests using Jest's test runner. This means you can leverage Jest's powerful features like mocking, snapshot testing, and parallel test execution.

const { defineFeature, loadFeature } = require('jest-cucumber');
const feature = loadFeature('./features/addition.feature');

defineFeature(feature, test => {
  test('Add two numbers', ({ given, when, then }) => {
    let calculator;

    given('I have entered 50 into the calculator', () => {
      calculator = new Calculator();
      calculator.enter(50);
    });

    given('I have entered 70 into the calculator', () => {
      calculator.enter(70);
    });

    when('I press add', () => {
      calculator.add();
    });

    then('the result should be 120 on the screen', () => {
      expect(calculator.result).toBe(120);
    });
  });
});

// Run the tests using Jest
// jest

Other packages similar to jest-cucumber

Keywords

FAQs

Package last updated on 25 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc