[英]Schema testing using Mocha Timeout Error
This is my Schema: 这是我的架构:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
//INDEX PAGE SCHEMA
const IndexSchema = new Schema({
bio: String
});
const IndexPageData = mongoose.model('indexpagedata', IndexSchema);
module.exports = IndexPageData;
this is my mocha code: 这是我的摩卡代码:
const assert = require('assert');
const mocha = require('mocha');
const MarioChar = require('../models/model');
// Describe our tests
describe('Saving records', function(){
// Create tests
it('Saves a record to the database', function(done){
var index = new IndexPageData({
bio: 'Mario ENTER BIO HERE'
});
char.save().then(function(){
assert(char.isNew === false);
done();
});
});
});
` `
Everytime I run this I get an error stating " Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves." 每次运行此命令时,我都会收到一条错误消息,指出“错误:超时超过2000毫秒。对于异步测试和挂钩,请确保调用了“ done()”;如果返回Promise,请确保它可以解决。”
mongoDB is already running in the background so I don't know what could be causing this issue. mongoDB已经在后台运行,所以我不知道是什么原因导致此问题。
I think you have two options. 我认为您有两种选择。
I usually insert both of them into my code. 我通常将它们都插入我的代码中。
// Add catch
describe('Saving records', function(){
// Create tests
it('Saves a record to the database', function(done){
var index = new IndexPageData({
bio: 'Mario ENTER BIO HERE'
});
char.save().then(function(){
assert(char.isNew === false);
done();
}).catch(done);
});
});
// Add time out
describe('Saving records', function(){
// Create tests
it('Saves a record to the database', function(done){
this.timeout(3000); // milli seconds
var index = new IndexPageData({
bio: 'Mario ENTER BIO HERE'
});
char.save().then(function(){
assert(char.isNew === false);
done();
}).catch(done);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.