Skip to content

Instantly share code, notes, and snippets.

@burt202
Created July 10, 2014 09:53
Show Gist options
  • Save burt202/12b34f271d6bc088222f to your computer and use it in GitHub Desktop.
Save burt202/12b34f271d6bc088222f to your computer and use it in GitHub Desktop.
Chai Custom Matcher
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