nodeJs上的assertEqual错误

时间:2013-04-01 11:34:43

标签: javascript jquery node.js mongodb

我刚开始使用nodejs开发。我正在测试mongodb驱动程序,但反复获取assertEquals没有方法。

来自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);
});

错误

没有方法'assertEquals'

如何解决它?

2 个答案:

答案 0 :(得分:1)

你可以使用Node's Assert(它被称为相等而不是等于* s *):

var assert = require('assert');

// ...
assert.equal(count, 1);
// ...

但是,对于单元测试或类似的东西,您应该考虑使用一些测试框架。例如。 Jasmine for Node,非常受欢迎。

答案 1 :(得分:0)

assert.equal已被弃用:改为使用assert.strictEqual()


assert.equal(1, '1');
// OK, 1 == '1'

assert.strictEqual(1, '1');
// FAIL, 1 === '1'

文档:https://nodejs.org/api/assert.html#assert_assert_equal_actual_expected_message