Given.js
Write DRY specs with lazy setup code
Given.js:
- Is inspired by RSpec's let helper method
- Keeps your spec setup code DRY
Examples:
- Testing an Angular.js directive
-
Can improve the performance of your tests
Variables defined using Given.js only spring into existence when referenced, so variables that are not used in every test do not incur a setup cost. This is contrary to a test suite where an entire fixture is constructed in a beforeEach function.
- Is test framework agnostic
Given.js will work with Mocha, Jasmine, Sinon and just about any other test framework you can think of. If it doesn't, it's a bug.
- Is comprehensivley tested
Given.js itself is written and maintained in a TDD-style and should be considered of a sufficient quality for production use.
- Produces helpful error messages when things go wrong
Given.js traps specific errors, for example, cyclic variable definitions and give you a meaningful error message rather than a raw stack overflow error.
given('foo', function() { return "I am " + this.bar; }); given('bar', function() { return "I am " + this.foo; }); this.bar // => "recursive definition of variable 'bar' detected"
- Installation:
Given.js can also be installed using bower (a package manager for frontend components, see bower.io for more details):
or by using npm$ bower install given
$ npm install given