Giter Site home page Giter Site logo

alhadis / mocha-when Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 16 KB

Write BDD-style tests with improved clarity and eloquence.

Home Page: https://npmjs.com/package/mocha-when

License: ISC License

JavaScript 42.18% Perl 57.82%
mocha bdd zero-config literate-testing

mocha-when's Introduction

Build Status: TravisCI Latest package version

“What's this?”

This is a drop-in enhancement for Mocha's BDD interface, which adds two small but tangible improvements:

A when() global

This is the same calling describe(), but the description you give is automatically prefixed by "When ":

when("this test is run", () => {
	it('gets prepended with the word "When"', );
});

Which is a shorter, clearer way of writing:

describe("when this test is run", () => );

Tests specified by it() actually start with "It "

Mocha makes idiomatic tests fun to write ...

describe("when the app starts", () => {
	it("activates successfully", () => );
	it("connects to the server", () => );
	it("receives a valid payload", () => );
});

... but not as fun to read:

when the app starts
  ✓ activates successfully
  ✓ connects to the server
  ✓ receives a valid payload
  ✓ displays the result

This module fixes such broken language by automatically prefixing each test:

when the app starts
  ✓ it activates successfully
  ✓ it connects to the server
  ✓ it receives a valid payload
  ✓ it displays the result

If a test (or suite) description already includes the expected prefix, it won't be modified. So you needn't worry about stuff like this:

when When the prefix is included
  ✓ it it won't repeat the word "it"
  ✓ it it'll check for contractions too

Usage

  1. Add mocha-when to your project's dependencies:

    # Using NPM:
    npm install --save-dev mocha-when
    
    # Or with Yarn:
    yarn add mocha-when
  2. Activate it by calling the function it exports:

    require("mocha-when")();

    Or simply pass mocha-when/register to Mocha's require option:

    // In your `.mocharc.js` file:
    module.exports = {
    	require: [
    		"mocha-when/register",
    	]
    };

Caveats

  • ESLint won't recognise the when() global, so add it to your globals list.
  • Mocha's ui option is assumed to be bdd (the default).
  • Tests can be declared without an it prefix using specify().
  • The enhancements applied by this module are persistent and irrevocable.

mocha-when's People

Contributors

alhadis avatar

Watchers

 avatar  avatar  avatar

Forkers

waldyrious

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.