0.24.0 • Published 6 years ago

gherkin-jest v0.24.0

Weekly downloads
661
License
ISC
Repository
github
Last release
6 years ago

gherkin-jest

Now you can run tests written in gherkin using jest.

Usage

First, install:

$ yarn add --dev gherkin-jest

Then, add to your jest config:

"transform": {
  "^.+\\.feature$": "gherkin-jest"
},
"setupFiles": ["<rootDir>/test/support"],
"testMatch": ["**/*.test.ts", "**/*.feature"],
"moduleFileExtensions": ["js", "jsx", "ts", "tsx", "feature"],

Define your steps in the setup file:

const { cucumber } = require('gherkin-jest');

cucumber.defineCreateWorld(() => {
  return {
    a: null,
    b: null,
    answer: null
  }
})

cucumber.defineRule('I have numbers {int} and {int}', (world, a, b) => {
  world.a = a;
  world.b = b;
});

cucumber.defineRule('I add them', (world) => {
  world.answer = world.a + world.b;
});

cucumber.defineRule('I get {int}', (world, answer) => {
  expect(world.answer).toBe(answer);
});

Write a test:

Feature: using feature files in jest
  As a developer
  I want to write tests in cucumber
  So that the business can understand my tests

  Scenario: a simple arithmetic test
    Given I have numbers 3 and 4
    When I add them
    Then I get 7

More documentation

This package just wraps the stucumber package to make a Jest transformer. More details on the flavour of Gherkin used and how to set up supporting code can be found in that package's documentation.

0.24.0

6 years ago

0.23.0

6 years ago

0.22.0

6 years ago

0.21.0

6 years ago

0.20.0

6 years ago

0.19.0

6 years ago

0.18.0

6 years ago

0.17.0

6 years ago

0.16.0

6 years ago

0.15.0

6 years ago

0.14.0

6 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago