开玩笑+猫鼬给错误模式与数组数组

时间:2020-02-17 10:11:11

标签: node.js mongodb mongoose jestjs

我正在使用以下模式对玩笑和猫鼬进行测试:

import mongoose from 'mongoose';

const PolygonSchema = new mongoose.Schema({
  type: {
    type: String,
    enum: ['Polygon'],
    required: true
  },
  coordinates: {
    type: [[[Number]]], // Array of arrays of arrays of numbers
    required: true
  }
});

export default PolygonSchema;

开玩笑地运行测试时,出现以下错误:

Test suite failed to run

    TypeError: _schemaType.caster.clone is not a function

      1 | import mongoose from 'mongoose';
      2 | 
    > 3 | const PolygonSchema = new mongoose.Schema({
        |                       ^
      4 |   type: {
      5 |     type: String,
      6 |     enum: ['Polygon'],

      at Schema.Object.<anonymous>.Schema.path (node_modules/mongoose/lib/schema.js:679:40)
      at Schema.add (node_modules/mongoose/lib/schema.js:444:12)
      at new Schema (node_modules/mongoose/lib/schema.js:121:10)
      at Object.<anonymous> (src/models/polygon.schema.js:3:23)
      at Object.<anonymous> (src/models/geofence.model.js:3:1)
      at Object.<anonymous> (src/services/geofence.service.js:3:1)
      at Object.<anonymous> (tests/services/geofence.test.js:5:1)

代码运行良好,仅凭开玩笑我会收到此错误。 我也在用babel-jest。

有任何解决办法吗? 谢谢你

0 个答案:

没有答案