Created
July 10, 2014 09:53
-
-
Save burt202/12b34f271d6bc088222f to your computer and use it in GitHub Desktop.
Chai Custom Matcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chai = require('chai'); | |
var expect = chai.expect; | |
var _ = require('underscore'); | |
chai.use(function (chai, utils) { | |
var Assertion = chai.Assertion; | |
Assertion.addMethod('created', function (expected, idKey) { | |
var obj = this._obj; | |
new Assertion(obj[idKey]).to.be.a('string'); | |
Object.keys(expected).forEach(function (key) { | |
new Assertion(obj).to.have.property(key, expected[key]); | |
}); | |
}); | |
}); | |
describe('Test', function() { | |
it('should do stuff', function() { | |
var genre = { | |
id: _.uniqueId(), | |
name: 'Jazz' | |
}; | |
expect(genre).to.be.created({ | |
name: 'Jazz' | |
}, 'id'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment