jasmine-def
Version:
Lazy test subjects for Jasmine inspired by RSpec
54 lines (41 loc) • 1.71 kB
Markdown
# jasmine-def
[](https://www.npmjs.com/package/jasmine-def)
[](https://travis-ci.org/vlazar/jasmine-def)
[](https://codeclimate.com/github/vlazar/jasmine-def)
[](https://codeclimate.com/github/vlazar/jasmine-def/coverage)
[](https://david-dm.org/vlazar/jasmine-def#info=devDependencies)
[](https://github.com/feross/standard)
Define lazily evaluated test data via ```def()``` and ```subject()``` functions.
## Usage
### Without jasmine-def
```javascript
describe('old spec', function () {
// order is important, options must be defined before subject
beforeEach(function () {
this.options = { foo: 'foo' };
});
beforeEach(function () {
this.subject = new SomeObject(this.options)
});
it('works', function () {
expect(this.options).toBeDefined();
expect(this.subject).toBeDefined();
});
});
```
### With jasmine-def
```javascript
describe('new shiny spec', function () {
// order is not important, defined properties are lazy evaluated
subject(function () {
return new SomeObject(this.options)
});
def('options', function () {
return { foo: 'foo' }
});
it('works', function () {
expect(this.options).toBeDefined();
expect(this.subject).toBeDefined();
});
});
```