I just started nodejs development. I am testing mongodb driver but repeatedly getting assertEquals has no method.
code from sourceRepo
var client = new Db('test', new Server("127.0.0.1", 27017, {})),
test = function (err, collection) {
collection.insert({a:2}, function(err, docs) {
collection.count(function(err, count) {
test.assertEquals(1, count);
});
// Locate all the entries using find
collection.find().toArray(function(err, results) {
test.assertEquals(1, results.length);
test.assertTrue(results[0].a === 2);
// Let's close the db
client.close();
});
});
};
client.open(function(err, p_client) {
client.collection('test_insert', test);
});
Error
has no method 'assertEquals'
How to reolve it?
You can use Node's Assert for this (where it is called equal rather than equal*s*):
var assert = require('assert');
// ...
assert.equal(count, 1);
// ...
However, for Unit tests or something similar you should consider using some testing framework. eg. Jasmine for Node, which is very popular.