All Projects → iensu → mocha-cakes-2

iensu / mocha-cakes-2

Licence: MIT license
A BDD plugin for Mocha testing framework

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mocha-cakes-2

Radish
Behavior Driven Development tooling for Python. The root from red to green.
Stars: ✭ 153 (+247.73%)
Mutual labels:  tdd, bdd, gherkin, cucumber
Gunit
GUnit - Google.Test/Google.Mock/Cucumber on steroids
Stars: ✭ 156 (+254.55%)
Mutual labels:  tdd, bdd, gherkin, cucumber
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+26243.18%)
Mutual labels:  mocha, tdd, bdd
Cucumber Rust
Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
Stars: ✭ 210 (+377.27%)
Mutual labels:  tdd, bdd, cucumber
Add
Разработка с управляемым качеством на 1С
Stars: ✭ 210 (+377.27%)
Mutual labels:  tdd, bdd, cucumber
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+1945.45%)
Mutual labels:  tdd, bdd, cucumber
Cypress Cucumber Example
An example skeleton with Cypress and Cucumber
Stars: ✭ 57 (+29.55%)
Mutual labels:  tdd, bdd, cucumber
White Bread
🍞 Story BDD tool for elixir using gherkin
Stars: ✭ 198 (+350%)
Mutual labels:  bdd, gherkin, cucumber
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+47595.45%)
Mutual labels:  mocha, tdd, bdd
Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (+1404.55%)
Mutual labels:  mocha, tdd, bdd
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-6.82%)
Mutual labels:  mocha, tdd, bdd
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+450%)
Mutual labels:  mocha, tdd, bdd
cucumber
Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
Stars: ✭ 322 (+631.82%)
Mutual labels:  tdd, bdd, cucumber
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-25%)
Mutual labels:  mocha, tdd, bdd
Nightwatch Cucumber
[DEPRECATED] Cucumber.js plugin for Nightwatch.js.
Stars: ✭ 243 (+452.27%)
Mutual labels:  bdd, gherkin, cucumber
docs
Cucumber user documentation
Stars: ✭ 110 (+150%)
Mutual labels:  bdd, gherkin, cucumber
Behat
BDD in PHP
Stars: ✭ 3,696 (+8300%)
Mutual labels:  bdd, gherkin, cucumber
Godog
Cucumber for golang
Stars: ✭ 1,287 (+2825%)
Mutual labels:  bdd, gherkin, cucumber
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (+727.27%)
Mutual labels:  mocha, tdd, bdd
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (+213.64%)
Mutual labels:  mocha, tdd, bdd

Mocha Cakes 2

Mocha Cakes is a Gherkin/Cucumber syntax integration for the Mocha testing framework.

Build Status Sponsored

Installation

NPM:

npm install --save-dev mocha-cakes-2

Usage

Enable the mocha-cakes-2 integration

To enable the Mocha integration you need to specify mocha-cakes-2 in the ui option.

CLI

Either use the command line argument:

mocha --ui mocha-cakes-2 path/to/my/tests

Or set it in your mocha.opts file:

--ui mocha-cakes-2

API

Either pass it in the options as you construct Mocha:

var mocha = new Mocha({
  ui: 'mocha-cakes-2'
});

Or set it after you've constructed Mocha:

var mocha = new Mocha();
mocha.ui('mocha-cakes-2')

Test structure

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.

Upgrading from version 1.x

Replace the require('mocha-cakes-2') statement(s) with the --ui mocha-cakes-2 option as described above.

TypeScript

The TypeScript definitions are bundled together with mocha-cakes-2. To use mocha directly with TypeScript you need types for mocha and ts-node.

npm install --save-dev typescript ts-node @types/mocha

You should have a tsconfig.json in the root of your project like so

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node"
  }
}

Now you can run it like so:

mocha -r ts-node/register --ui mocha-cakes-2  ...

Your tests should look like this:

import 'mocha-cakes-2';

Feature('Some feature', () => {

  Scenario('Some Scenario', () => {

    let number = 2;

    Given('a number', () => {

    });
    And('that number is 2', () => {

    });

    When('adding 40', () => {

    });

    Then('the number should be 42', () => {

    });
  });
});

API

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

.skip

Skips a test clause. Works on all test functions.

Feature('Some feature', () => {

  Scenario.skip('Skipped scenario', () => {
    // ...
  });

  Scenario('Ordinary', () => {
    // ...
  });
});

.only

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!', () => {
    // ...
  });

  // ...
});

beforeEachScenario and afterEachScenario

Executes the provided function only once for each of the scenarios under the current scope.

Feature('Some feature', () => {

  beforeEachScenario( () => {
    someSetup();
  });

  afterEachScenario( () => {
    doCleanup();
  });

  Scenario('First scenario', () => {
    // ...
  });

  Scenario('Second scenario', () => {
    // ...
  });

  // ...
});

beforeEachFeature and afterEachFeature

Executes the provided function only once for each of the features under the current scope.

beforeEachFeature( () => {
  someSetup();
});

afterEachFeature( () => {
  doCleanup();
});

Feature('Some feature', () => {
  // ...
});

Feature('Another feature', () => {
  // ...
});

// ...

Development

Testing the CLI and API interfaces

If you use Mocha directly to run the tests you can set the MOCHA_INTERFACE environment variable to either cli or api to choose which Mocha interface to run the tests with: MOCHA_INTERFACE=api mocha test/feature/tests.js.

MOCHA_INTERFACE will default to cli if no value is set.

When you run npm run test:cli or npm run test:api (or npm test to run them both), MOCHA_INTERFACE is set automatically to the appropriate value.

Acknowledgements

Mocha Cakes 2 is heavily influenced by quangv's mocha-cakes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].