2015-01-05 2 views
1

나는 mongoose를 사용하여 mongodb에 연결하는 chai 테스트를 실행하려고 시도하고 있지만 '예상되지 않은 값이 오브젝트'로 실패하고 있습니다. 나는 기능하는 응용 프로그램에서 사용하는 것과 같은 방법을 사용하고 있습니다. 데이터베이스에 올바르게 연결하고 있습니까? 당신이 연결이 완료되면 주장이 일어날 수 있도록 할 필요가 있으므로 몽고에 대한 연결이 비동기이기 때문에 당신은 test is asynchronous있어테스트 내에서 몽구스에 연결할 수 있습니까?

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');   

}); 
+0

? 편집 : 신경 쓰지 마라 ... 대답오고 ... – jakerella

+0

어떤 다른 테스트 프레임 워크를 사용하고 계십니까? 내 말은, '시험'이란 무엇입니까? – lante

답변

1

:

당신이 그 오류가 무엇 라인
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) 
}); 
관련 문제