You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

bdd-lazy-var

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bdd-lazy-var

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

0.0.1
Source
npmnpm
Version published
Weekly downloads
16K
-6.37%
Maintainers
1
Weekly downloads
 
Created
Source

Mocha BDD + lazy variable definition (aka rspec)

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

Installation

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

Browser version: bdd-lazy-var.js.Node version: index.js.

How to use

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

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

Features

  • all variables are defined lazily, so order doesn't matter.
  • subject accessor as alias for def('subject', ...) and get('subject')
  • ability to redefine outer 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 subejct)
  • all variables are cleaned after each test

Examples

describe('Suite', function() {
  def('fullName', function() {
    return get('firstName') + '+' + get('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');
    });
  });
});

FAQs

Package last updated on 27 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts