I'm writing a node module that collects data from a web page using cheerio. The module calls back with the collected data as an object, like this:
module.exports = function collect(callback) {
var data = {
item1: '',
item2: '',
item3: ''
};
callback(null, data);
}
I'm trying to decide how to test this. I'm inclined to create an expected object and compare it to what I actually received. I plan on using mocha and assert, so this test would look something like this:
describe('collect()', function() {
it('should give me the expected data', function(done) {
var expected = {
item1: '',
item2: '',
item3: ''
};
collect(function(err, actual) {
assert.deepEqual(actual, expected);
done();
});
});
});
My main gripe with this solution is that I cannot individually test each piece of data. For example, item1 and item2 might equal what was expected, but item3 does not, therefore failing the whole test. Is there a better solution here?
Aucun commentaire:
Enregistrer un commentaire