JSPM

  • Created
  • Published
  • Downloads 27300
  • Score
    100M100P100Q149128F
  • License MIT

Provides "ui" for mocha.js which allows to define lazy variables and subjects

Package Exports

  • bdd-lazy-var

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bdd-lazy-var) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Mocha BDD + lazy variable definition (aka rspec) Build Status

Provides "ui" for mocha.js which allows to define lazy variables and subjects.

Installation

npm install bdd-lazy-var --save-dev

Browser versions: bdd_lazy_var.js, bdd_lazy_var_global.js, bdd_lazy_var_getter.js. Node versions: index.js, global.js, getter.js.

How to use

Command line: mocha -u bdd-lazy-var or in JavaScript:

var mocha = new Mocha({
  ui: 'bdd-lazy-var'
});

If you want to access vars using more readable form use bdd-lazy-var/global or bdd-lazy-var/getter ui.

Features

  • all variables are defined lazily, so order doesn't matter.
  • subject accessor as an alias for def('subject', ...) and get('subject')
  • ability to redefine parent's variable
  • fallback to parent's variables
  • fallback to parent's variable inside the same definition (i.e. subject inside subject definition will refer to parent's subject)
  • all variables are cleaned after each test
  • get.variable or get.definitionOf for creating getters for variables
  • access variables using:
    • this.variableName (i.e. this.fullName)
    • get(variableName) (i.e. get('fullName'))
    • $variableName (i.e. $fullName, only with bdd-lazy-var/global)
    • get.variableName (i.e. get.fullName, only with bdd-lazy-var/getter)

Examples for bdd-lazy-var

describe('Suite', function() {
  def('fullName', function() {
    return this.firstName + '+' + this.lastName;
  });

  def('firstName', 'BDD');
  def('lastName', 'Lazy variable');

  it('computes variables', function() {
    expect(get('fullName')).to.equal('BDD+Lazy variable');
  });

  describe('Nested suite', function() {
    def('fullName', function() {
      return get('fullName') + '!'; // get parent's "fullName" variable
    });

    it('gets parent variable', function() {
      expect(get('fullName')).to.equal('BDD+Lazy variable!');
    });
  });

  describe('Another nested suite', function() {
    def('lastName', 'Rocks!');

    it('redefines parent variable', function() {
      expect(get('fullName')).to.equal('BDD+Rocks!');
    });
  });

  describe('with subject', function() {
    subject(function() {
      return {};
    });

    it('defines subject', function() {
      expect(subejct()).to.be.an('object');
    });

    it('can be retrieved via `this`', function() {
      expect(this.subject).to.equal(subject());
    });
  });
});

Examples for bdd-lazy-var/global

describe('Array', function() {
  subject(function() {
    return [ 1, 2, 3 ];
  });

  it('has 3 elements by default', function() {
    expect($subject).to.have.length(3);
  });
});

Examples for bdd-lazy-var/getter

describe('Suite', function() {
  subject(function() {
    return new Suite();
  });

  it('has parent', function() {
    expect(get.subject).to.have.keys('parent');
  });
});