我试图嘲弄我的猫鼬schemas.with这段代码:
// report.schema.js
import mongoose, { Schema } from 'mongoose';
const reportSchema = new Schema(
{
data:{
type: string
},
},
{ timestamps: true }
);
export default mongoose.model('Report', reportSchema);在我的测试中:
import mockingoose from "mockingoose";
import Report from "../mongodb/models/report";
mockingoose(Report).toReturn({ data: "some_foo" }, "findOne");错误是:
● Test suite failed to run
TypeError: (0 , _mockingoose.default) is not a function
1 | import mockingoose from "mockingoose";
2 | import Report from "../mongodb/models/report";
> 3 | mockingoose(Report).toReturn({ data: "some_foo" }, "findOne");发布于 2022-08-02 18:13:32
我解决了这个问题:
var bookMock = sinon.mock(new Book({ title: 'Rayuela', author: 'Julio Cortazar' }));
var book = bookMock.object;我使用了这个链接https://github.com/underscopeio/sinon-mongoose/blob/master/examples/promises/test.js

发布于 2022-03-25 13:31:24
我自己解决不了这个问题。如果可以的话我会给你回电话的。现在,作为一种解决办法,您可以使用
// @ts-expect-error TS7016
import * as mockingoose from 'mockingoose'在我的项目中,由于某种原因,"esModuleInterop": true,无法工作。此外,我将提供我的tsconfig.json,以防万一:
{
"compilerOptions": {
"strict": true,
"target": "ES2021",
"declaration": true,
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
"lib": ["ES2021"],
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"importsNotUsedAsValues": "preserve"
}
}发布于 2022-07-20 17:01:12
错误信息:
TypeError:(0,mockingoose_1.default)不是函数
在我的例子中,通过将语法ES6导入/导出为CommonJS解决了这个问题。
在此之前:
import mockingoose from "mockingoose"之后:
const mockingoose = require("mockingoose");https://stackoverflow.com/questions/70156753
复制相似问题