Socket
Book a DemoInstallSign in
Socket

gherkin-easy

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gherkin-easy

Minimalistic Gherkin testing for JavaScript

1.2.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

gherkin-easy

Minimalistic Gherkin testing for JavaScript

Build Status

Prerequisites

  • Node.js v6 +
  • Test runner such as Jest or Mocha

Install

$ npm install gherkin-easy

Getting Started

  • Create a gherkin feature file:

# ./withdraw-cash.feature

Feature: Withdraw Cash

    Scenario Outline: Withdraw cash from bank account
        Given my account balance is <startingBalance> dollars
        When I withdraw <withdrawAmount> dollars from my account
        Then my account should have a remaining balance of <remainingBalance> dollars

        Examples:
            | startingBalance | withdrawAmount | remainingBalance |
            | 100             | 50             | 50               |
            | 100             | 0              | 100              |
            | 100             | 1.25           | 98.75            |
            | 1               | 0.50           | 0.50             |
            | 1               | 5.00           | -4.00            |

  • Create feature code:

// ./bank-account.js

class BankAccount {

    constructor(balance = 0) {
        this.balance = balance;
        this.withdraw = this.withdraw.bind(this);
    }

    withdraw(amt = 0) {
        this.balance = this.balance - amt;
        return amt;
    }

    getBalance() {
        return this.balance;
    }
}

module.exports = BankAccount;

  • Create test code:

// ./__tests__/withdraw-cash-test.js

const FeatureTest = require('gherkin-easy');
const BankAccount = require('../bank-account');
const featureTest = new FeatureTest('../withdraw-cash.feature');

featureTest.run(({ given, when, then, example }) => {

    let account;

    beforeAll(() => {
        account = new BankAccount(example.startingBalance);
    });

    test(given, () => {
        expect(account.getBalance()).toBe(example.startingBalance);
    });

    test(when, () => {
        expect(account.withdraw(example.withdrawAmount)).toBe(example.withdrawAmount);
    });

    test(then, () => {
        expect(account.getBalance()).toBe(example.remainingBalance);
    });
});

  • Run test (using Jest CLI in this example):

$ jest -->


PASS  examples/__tests__/withdraw-cash-test.js
 Feature: Withdraw Cash
   Scenario: Withdraw cash from bank account | Example 1
     ✓ Given my account balance is 100 dollars (2ms)
     ✓ When I withdraw 50 dollars from my account
     ✓ Then my account should have a remaining balance of 50 dollars
   Scenario: Withdraw cash from bank account | Example 2
     ✓ Given my account balance is 100 dollars
     ✓ When I withdraw 0 dollars from my account
     ✓ Then my account should have a remaining balance of 100 dollars (1ms)
   Scenario: Withdraw cash from bank account | Example 3
     ✓ Given my account balance is 100 dollars
     ✓ When I withdraw 1.25 dollars from my account
     ✓ Then my account should have a remaining balance of 98.75 dollars (1ms)
   Scenario: Withdraw cash from bank account | Example 4
     ✓ Given my account balance is 1 dollars
     ✓ When I withdraw 0.5 dollars from my account
     ✓ Then my account should have a remaining balance of 0.5 dollars
   Scenario: Withdraw cash from bank account | Example 5
     ✓ Given my account balance is 1 dollars
     ✓ When I withdraw 5 dollars from my account
     ✓ Then my account should have a remaining balance of -4 dollars

Keywords

gherkin

FAQs

Package last updated on 28 Sep 2018

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.