Skip to content

assertEqual error on nodeJs

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("", 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
    };, p_client) {
  client.collection('test_insert', test);


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.