Skip to content

lo1tuma/mocha-bdd-when

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM Version Build Status devDependencies

mocha-bdd-when

Allows to execute tests conditionally

How to use

var when = require('mocha-bdd-when');

when(true).describe('Test Suite', function () {
    when(false).it('should do something', function () {
        // ...
    });
});

Advanced example

Consider you are writing a test for an isomorphic module that runs on the server and the client. It would be a good idea to run the unit tests of such an isomorphic module in every environment it is supposed to be executed in.

In an isomorphic module there might exist some code that gets triggered only on the client and is ignored on the server. This could be an event handler which gets triggered in the browser after a click event was triggered. It would be hard and not very useful to trigger a click event in the node environment. So you want to run this specific test case only in the browser.

var when = require('mocha-bdd-when'),
    runInBrowser = typeof window !== 'undefined';

describe('isomorphic module', function () {

    when(runInBrowser).it('should do something when a button is clicked' function () {
        // trigger a click event
        // assert that something happened after the click
    });

    it('should work in every environment', function () {
        // assert some environment agnostic logic
    });

});

About

Allows to execute tests conditionally

Resources

License

Stars

Watchers

Forks

Packages

No packages published