# gherkin-easy

> Minimalistic Gherkin testing for JavaScript

Latest version **1.2.0** (published 2018-09-28) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install gherkin-easy
pnpm add gherkin-easy
yarn add gherkin-easy
bun add gherkin-easy
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2018-09-28 |
| First published | 2017-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Eric Zingeler |
| Maintainers | eezing |
| Keywords | gherkin, jest, unit, testing, mocha, test, javascript, node, bdd, tdd |

## Links

- npm: https://www.npmjs.com/package/gherkin-easy
- Repository: https://github.com/eezing/gherkin-easy
- Homepage: https://github.com/eezing/gherkin-easy#readme
- Issues: https://github.com/eezing/gherkin-easy/issues
- npm.io page: https://npm.io/package/gherkin-easy

## Dependencies (1)

- [gherkin](https://npm.io/package/gherkin.md) ^4.1.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2018-09-28
- 1.1.1 — 2018-09-24
- 1.1.0 — 2018-09-24
- 1.0.5 — 2017-03-27
- 1.0.4 — 2017-03-27
- 1.0.3 — 2017-03-27
- 1.0.2 — 2017-03-27
- 1.0.1 — 2017-03-27
- 1.0.0 — 2017-03-27

## README

# gherkin-easy

Minimalistic Gherkin testing for JavaScript

[![Build Status](https://travis-ci.org/eezing/gherkin-easy.svg?branch=master)](https://travis-ci.org/eezing/gherkin-easy)

## Prerequisites

- Node.js v6 +
- Test runner such as [Jest](https://facebook.github.io/jest) or [Mocha](https://mochajs.org)

## Install

    $ npm install gherkin-easy

## Getting Started

1. Create a gherkin feature file:

```gherkin

# ./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            |

```

2. Create feature code:

```javascript

// ./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;

```

3. Create test code:

```javascript

// ./__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);
    });
});

```

4. Run test (using Jest CLI in this example):

``` $ jest ``` -->

```shell

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
  ```

---
_Source: https://npm.io/package/gherkin-easy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
