Socket
Socket
Sign inDemoInstall

bdd-lazy-var

Package Overview
Dependencies
0
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

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


Version published
Maintainers
1
Install size
28.6 kB
Created

Readme

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 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 subejct)
  • all variables are cleaned after each test
  • get.variable or get.definitionOf for creating getters for variables

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');
    });
  });
});

Keywords

FAQs

Last updated on 13 Dec 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc