Mocha Cakes is a Gherkin/Cucumber syntax integration for the Mocha testing framework.
NPM:
npm install --save-dev mocha-cakes-2
You need to specify mocha-cakes-2
as a mocha integration by adding the option --ui mocha-cakes-2
to your mocha
command:
mocha --ui mocha-cakes-2 path/to/my/tests
You can also specify it in your mocha.opts
file:
--ui mocha-cakes-2
require('chai').should();
Feature('Some feature', () => {
Scenario('Some Scenario', () => {
let number = 2;
Given('a number', () => {
number.should.exist;
});
And('that number is 2', () => {
number.should.equal(2);
});
When('adding 40', () => {
number += 40;
});
Then('the number should be 42', () => {
number.should.equal(42);
});
});
});
The result will look something like this:
The common Mocha functions (describe
, it
, before
, after
, etc) are also available and can be used together with Mocha Cakes.
Replace the require('mocha-cakes-2')
statement(s) with the --ui mocha-cakes-2
option as described above.
The Mocha Cakes integration adds the following functions to the global scope:
Feature | feature
Scenario | scenario
Given | given
When | when
Then | then
And | and
But | but
Skips a test clause. Works on all test functions.
Feature('Some feature', () => {
Scenario.skip('Skipped scenario', () => {
// ...
});
Scenario('Ordinary', () => {
// ...
});
});
Only run the specified test clause. Works on all test functions.
Feature('Some feature', () => {
Scenario('First scenario', () => {
// ...
});
Scenario('Second scenario', () => {
// ...
});
Scenario.only('Only I will run!', () => {
// ...
});
// ...
});
Mocha Cakes 2 is heavily influenced by quangv's mocha-cakes.