Cucumber for Javascript

Notes on tutorials of Cucumber School

The focus on cucumber is in BDD style. It emphaizes on nontechnical documentation with code support for verification.

Code examples are from Cucumber School.

It is more intuitive to non-programmers.

(?:I/You) have {int} cucumber(s) in my belly/stomach \(amazing!)

# {int} - type (int, float, word, string, and {} as any
# (s) - optional
# belly/stomach - either belly or stomach
# \(amazing!) - escape match `(amazing!)` in text
# (?:I/You) - optional, and it is not capture as a parameter

Try the expression here
Check the syntax here

import { defineParameterType } from '@cucumber/cucumber';

defineParameterType({
name: 'color',
regexp: /red|blue|yellow/,
transformer: s => new Color(s),
});
Feature: a feature
Scenario: a scenario
Given a table step
| Vegetable | Rating |
| Apricot | 5 |
| Brocolli | 2 |
| Cucumber | 10 |
import { Given } from '@cucumber/cucumber';
import * as assert from 'assert';

Given(/^a table step$/, function(table) {
const expected = [
{'Vegetable': 'Apricot', 'Rating': '5'},
{'Vegetable': 'Brocolli', 'Rating': '2'},
{'Vegetable': 'Cucumber', 'Rating': '10'},
];
assert.deepEqual(table.hashes(), expected);
});

Check here to further details

Global states can be shared and be accessed across step definition using function declaration.

When(
"{?:person} go(es) to {destination} by {vehicle}",
function (destination, vehicle) {
const vehicle = Vechicle();
this.timeTaken = vehicle.travelTime(destination);
}
);

Then(
"It spends {time}",
function(expectedTime) {
assert.equal(this.timeTaken, expectedTime);
}
);

Run the test suite with formatter rerun

npm test -- -f rerun:@rerun.txt # will export the result to rerun.txt

Say the scenario failed, the filererun.txt will be generated with the following content (using the line number filtering format)

http://features/hear_shot.feature:38

You can re-run the failed scenario by

npm test -- @rerun.txt

Think carefully whether cucumber is a testing tool or documentation tool. A lengthy steps have no benefit as a dcoumentation. If you want someone to go for it, you need to know how to write a prose in gherkin.

B is for Business Language
use plain language, avoid domain jargon

R is for Real Data
use more approachable names (like Peter, Mary)

I is for Intention Revealing
only reveal relevant detail, usually those will be observed by users

E is for Essential
further refined/removed steps after the intention revealing

F is for Focused
make it precise

When you are imperative, you are exactly instructing in details.
Like programming, imperative style is to command the computer sequence entirely.

However, if you are going for declarative you only need to describe the actual outcome, things like the execution sequence, or how the computer achieves the outcome, you might not have a full context. It is very good for nontechnical people to know that.

Three Amigos — Tester, Developer and Product Owner
Example Mapping — Set up an example to go further (Business Rules, Real Life Examples, Questions and Assumptions, Simplify the rules)
Incidental Details
Discovery, formulation and Automation — find unknown unknown
Deliberate Discovery

Resource:

Cucumber School (JS)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam00

Let's go invent tomorrow instead of worrying about what happened yesterday.