Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

burtcorp/mocha-define

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocha define

Mocha define is a small plugin for Mocha.js that provides lazy test definitions.

Installation

$ npm install mocha-define --save-dev

Usage

Require mocha-define in the Mocha tests.

This plugin defines two functions: def and subject.

For example:

describe('Car', function() {
  def('engine', function() {
    return new Engine;
  });

  def('options', function() {
    return {};
  });

  subject(function() {
    return Car(this.engine, this.options);
  });

  describe('#start', function() {
    it('starts the engine', function(done) {
      this.engine.start = done;
      this.subject.pressStartButton();
    });
  });

  describe('#burnout', function() {
    it('trashes the tires', function(done) {
      this.subject.on('burnout', function(status) {
        if (status.tires === 'GARBAGE') {
          done();
        }
        this.subject.doThatBurnout();
      });
    });
  });
});

Contribution

Be sure to!

Implement the functionality with a test and send us a pull request on Github.