I just started nodejs development. I am testing mongodb driver but repeatedly getting assertEquals has no method.
code from sourceRepo
JavaScript
x
23
23
1
var client = new Db('test', new Server("127.0.0.1", 27017, {})),
2
test = function (err, collection) {
3
collection.insert({a:2}, function(err, docs) {
4
5
collection.count(function(err, count) {
6
test.assertEquals(1, count);
7
});
8
9
// Locate all the entries using find
10
collection.find().toArray(function(err, results) {
11
test.assertEquals(1, results.length);
12
test.assertTrue(results[0].a === 2);
13
14
// Let's close the db
15
client.close();
16
});
17
});
18
};
19
20
client.open(function(err, p_client) {
21
client.collection('test_insert', test);
22
});
23
Error
has no method ‘assertEquals’
How to reolve it?
Advertisement
Answer
You can use Node’s Assert for this (where it is called equal rather than equal*s*):
JavaScript
1
6
1
var assert = require('assert');
2
3
// ...
4
assert.equal(count, 1);
5
// ...
6
However, for Unit tests or something similar you should consider using some testing framework. eg. Jasmine for Node, which is very popular.