Coder Social home page Coder Social logo

jasmine-let's Introduction

jasmine-let

Lazy variable evaluation for Jasmine specs, inspired by Rspec's let.

Installation

$ component install xaethos/jasmine-let

Example

Get a reference to the jasmine let function. As a Component:

var lazy = require('jasmine-let')(
  jasmine, // A reference to jasmine
  window   // The object where the variables should be attached
);

Or if you simply link jasmine-let.js:

var lazy = jasmineLet(jasmine, window);

That's it! Use it in your specs.

describe("A lazily evaluated variable", function () {

  lazy("fooSquare", function () { return foo * foo; });
  lazy("foo", 9);
  lazy("boom", function () { throw "better not call this"; });

  it("only gets evaluated when referenced", function () {
    expect(fooSquare).toEqual(81);
  });

  describe("in a nested describe block", function () {

    lazy("boom", function () { return "bomb defused"; });

    it("overrides definitions in outter blocks", function () {
      expect(function(){ boom; }).not.toThrow();
    });

  });
});

When called with the evaluateBefore: true option, it will evaluate the declaration before the spec (i.e. it behaves like RSpec's let!). It is easiest to use this be creating a wrapper method.

var eager = function (name, declaration) {
  lazy(name, declaration, { evaluateBefore: true });
};

describe("evaluateBefore option", function () {
  var evaluated = false;

  eager('foo', function () { evaluated = true; });

  it("evaluates a definition before the specs (default: false)", function () {
    expect(evaluated).toBeTruthy();
  });
});

License

MIT. See LICENSE file.

jasmine-let's People

Contributors

xaethos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.