A simple set of tools for comparing given and expected results. It is meant to be semantically clear and concise, returning a simple truthy response. This is ideal for testing.
To use jdg throughout your project:
$ npm install --save jdg
To only use jdg for testing, add jdg to your devDependencies and:
$ npm install jdg
A testing example using mocha and shouldjs:
var jdg = require('jdg');
var should = require('should');
describe('GET /users', function() {
it('should include Bob', function() {
var users = someRequest('/users');
jdg.isInArray(users, {name: 'Bob', id: 4}).should.equal(true);
});
});
And an example using jdg outside of your testing suite:
var jdg = require('jdg');
function updateUser(user, attrs, opts) {
attrs.forEach(function(attr) {
if (jdg.isInArray(user.baseAttrs, attr)) {
// do something
}
});
}
Jdg's underlying helpers is
and get
are also exposed for use:
function updateUser(user, attrs, opts) {
if (jdg.is.missing(user)) {
// throw some error
} else {
var userAttrs = judge.get.keys(user);
// do something
}
}
If you're using jdg and find a problem, feel free to report the issue here on Github. This helps determine if an issue has already been reported and if there is a fix already in progress.