【问题标题】:MongoDB and MochaMongoDB和摩卡
【发布时间】:2020-07-18 09:52:13
【问题描述】:

有人在他们的 mocha 测试中使用过 async/await 吗?

我正在创建这个简单的测试来检查我的代码是否成功地将对象保存到数据库:

const mocha = require('mocha');
const assert = require('assert');
const marioChar = require('../models/mariochar');

async function saveAMarioChar (paramname,paramweight) {
    var char = new marioChar({
        name: paramname,
        weight: paramweight
    });

    const saveresult = await char.save()
    return !saveresult.isNew;

} 

describe(
    'saving record',

    () => {

        it('Save a mariochar',
            async ()  => {
                const result = await saveAMarioChar('luigi',64);
                assert(result)
            }
        )
    }
)

【问题讨论】:

    标签: mongodb mocha.js


    【解决方案1】:

    抱歉,麻烦各位了,这段代码运行良好,我在创建架构时使用了“mongooose”和三个“o”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 2012-05-20
      • 2015-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多