2
從REPL連接到MongoDB的正常工作:無法連接從摩卡測試
> var mongoose=require('mongoose');
undefined
> mongoose.connect('mongodb://localhost/test', function(error) {
... console.log('connected\n%s\n', error);
... });
回報:
{ connections:
[ { base: [Circular],
collections: {},
models: {},
replica: false,
hosts: null,
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
name: 'test',
options: [Object],
_readyState: 2,
_closeCalled: false,
_hasOpened: false,
_listening: false,
_events: {},
db: [Object] } ],
plugins: [],
models: {},
modelSchemas: {},
options: {} }
> connected # Yes!
undefined
但從摩卡測試套件連接不工作:
var mongoose = require('mongoose');
console.log('connecting...');
mongoose.connect('mongodb://localhost/test', function(error) {
if(error) console.error('Error while connecting:\n%\n', error);
console.log('connected');
});
回報:
$ mocha
connecting...
0 passing (0 ms)
有誰知道爲什麼這不起作用?
當我RUND這個代碼我得到'類型錯誤:做不是function',看到https://stackoverflow.com/questions/46294310/mocha-mongoose-done-is-not-a-function- wdio - 摩卡框架 – Gobliins