gpt4 book ai didi

node.js - "mpromise (mongoose' s 默认 promise 库)已弃用“测试时出现错误

转载 作者:IT老高 更新时间:2023-10-28 13:09:34 25 4
gpt4 key购买 nike

一段时间以来,我一直收到此错误,我决定今天修复它,但在尝试修复它一个小时后,我找到了解决方案。

当我测试我的 Mongoose 用户模型时,会生成此错误/警告:

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 有关,但我不知道如何修复它。有人可以帮助我并告诉我如何修复它,以便不显示错误/警告。

最佳答案

你需要插入一个promise库(q、bluebird、es6 one...)

mongoose.Promise = require('bluebird');

关于node.js - "mpromise (mongoose' s 默认 promise 库)已弃用“测试时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39333229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com