“不赞成使用mpromise(猫鼬的默认诺言库)".测试时出现错误 [英] "mpromise (mongoose's default promise library) is deprecated" error when testing
本文介绍了“不赞成使用mpromise(猫鼬的默认诺言库)".测试时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一段时间以来,我一直收到此错误,我决定今天进行修复,但是尝试修复一个小时后,我可以找到解决方案.
For a while I have been getting this error and I decided to fix it today but after an hour trying to fix it I can find the solution.
当我测试猫鼬用户模型时,会生成此错误/警告:
When I test my mongoose User model this error/warning is generated:
Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
这是我的考试:
1 var assert = require('chai').assert;
2 var mongoose = require('mongoose');
3 var clearDB = require('mocha-mongoose')(require('../../config/database').uri, { skip: ['workouts'] });
4 var database = require('../../config/database').connect;
5
6 var User = require('../../app/models/user');
7 var user = new User({});
8
9 var req_body = {
10 username: "garyvee",
11 email: "gary@vaynermedia.com",
12 password: "secret"
13 };
14
15 describe('User', function() {
16 beforeEach(function(done) {
17 user.username = "johnsmith";
18 user.email = "john@gmail.com";
19 user.password = "secret";
20 done();
21 });
22
23 it('can be saved', function() {
24 return user.save(function(err: any) {
25 assert.isNull(err);
26 })
27 });
28 });
我认为它与.save
有关,但我不知道如何解决.有人可以帮我,告诉我如何解决它,以便不显示错误/警告.
I think it has something to do with the .save
but I don't know how to fix it. Can someone help me and tell me how to fix it so that error/warning isn't shown.
推荐答案
您需要插入一个Promise库(q,bluebird,es6一个...)
You need to plugin a promise library (q, bluebird, the es6 one...)
mongoose.Promise = require('bluebird');
这篇关于“不赞成使用mpromise(猫鼬的默认诺言库)".测试时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文