【问题标题】:Mongoose MissingSchemaError with Mocha testMongoose MissingSchemaError 与 Mocha 测试
【发布时间】:2013-08-12 19:16:03
【问题描述】:

我正在尝试使用 mocha 测试我的 API,但每次我在使用 populate(field) 的模型上调用方法时,它都会失败并显示 Uncaught MissingSchemaError: Schema hasn't been registered for model "Kitchen". Use mongoose.model(name, schema)。

最小示例:https://gist.github.com/connors511/6204164(transaction.js 是违规者)

我也尝试过将该方法用作 schema.statics,但它返回的结果与示例相同。

如果我从 _listForUserClub 方法中删除 populate('where.kitchen'),则 MissingSchema Club 会失败。

知道是什么原因造成的,或者如何解决?

【问题讨论】:

    标签: node.js unit-testing mongoose mocha.js


    【解决方案1】:

    我已经通过使用解决了这个问题

    var _model;
    try {
        _model = mongoose.model('ClubTest', _schema);
        _model.singular = 'clubtest';
    } catch(e) {
        _model = mongoose.model('ClubTest');
    }
    

    而不是

    var _model = mongoose.model('ClubTest', _schema);
    _model.singular = 'clubtest';
    

    在https://groups.google.com/d/msg/mongoose-orm/PXTjqqpaDFk/tYx1ge04GlsJ找到解决方法后我的所有模型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-11
      • 2016-11-19
      • 2018-11-05
      • 2016-01-08
      • 2015-11-01
      • 2017-06-10
      • 2023-03-07
      • 2015-01-04
      相关资源
      最近更新 更多