操作不正确的状态:“新的”允许状态:“ [运行,启动]”
我正在测试只有一个测试案例。我验证了mongodb方法,它们似乎要达到 日期。 Github也没有开放问题。
Error: at MongoMemoryServer.getUri (node_modules/mongodb-memory-server-
core/src/MongoMemoryServer.ts:706:15)
at src/test/setup.ts:7:32
at src/test/setup.ts:8:71
at Object.<anonymous>.__awaiter (src/test/setup.ts:4:12)
at Object.<anonymous> (src/test/setup.ts:5:22)
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
let mongo: any;
beforeAll(async () => {
mongo = new MongoMemoryServer();
const mongoUri = await mongo.getUri();
await mongoose.connect(mongoUri);
});
beforeEach(async () => {
const collections = await mongoose.connection.db.collections();
for (let collection of collections) {
await collection.deleteMany({});
}
});
afterAll(async () => {
await mongo.stop();
await mongoose.connection.close();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
频道行
mongo = new Mongomemoryserver();
tomongo =等待mongomemoryserver.create()
channge the line
mongo = new MongoMemoryServer();
tomongo = await MongoMemoryServer.create()
我遇到了同样的问题,然后查看我想知道您首先必须使用
new
创建对象,然后使用start()启动实例:I had your same issue and by looking at the documentation I figure out that you first have to create the object with
new
and then start the instance with start():您有2个解决此问题的选项:
1-更改行:
TO:
2-更改行:
to::
You have 2 options to solve this problem:
1- Change the line:
to:
2- Change the lines:
To: