Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我可以在测试中连接到mongoose吗?_Node.js_Mongodb_Chai - Fatal编程技术网

Node.js 我可以在测试中连接到mongoose吗?

Node.js 我可以在测试中连接到mongoose吗?,node.js,mongodb,chai,Node.js,Mongodb,Chai,我正在尝试运行一个使用mongoose连接mongodb的chai测试,但由于“预期未定义为对象”而失败。我使用的方法与我在功能应用程序中使用的方法相同。我是否正确连接到数据库 var expect = require('chai').expect; var eeg = require('../eegFunctions'); var chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); chai.use

我正在尝试运行一个使用mongoose连接mongodb的chai测试,但由于“预期未定义为对象”而失败。我使用的方法与我在功能应用程序中使用的方法相同。我是否正确连接到数据库

var expect = require('chai').expect;
var eeg = require('../eegFunctions');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
var mongoose = require('mongoose');
var db = mongoose.connection;

db.on('error', console.error);
db.once('open', function callback(){console.log('db ready');});

mongoose.connect('mongodb://localhost/eegControl');

test("lastShot() should return an object", function(){

    var data;
    eeg.lastShot(function(eegData){
        data = eegData;
    });
    return expect(data).to.eventually.be.an('object');        

});
这是因为与Mongo的连接是异步的,因此需要在连接完成时进行断言:

test("lastShot() should return an object", function(done){  // Note the "done" argument

    var data;
    eeg.lastShot(function(eegData){
        data = eegData;

        // do your assertions in here, when the async action executes the callback...
        expect(data).to.eventually.be.an('object');

        done(); // tell Mocha we're done with async actions
    });

    // (no need to return anything)
});

你在哪一行看到这个错误?编辑:无需担心。。。回答来了…你在使用什么其他的测试框架?我的意思是,什么是
test