我有koa app
和jest测试框架,app
包裹http.createServer
并连接到mongo
mongooseConnect();
const app = new Koa();
initHandlers(app);
app.use(routes);
export default http.createServer(app.callback());
测试后,supertest不关闭服务器,测试示例
test('success create user', (done) => {
return supertest(app)
.post(`/api/auth/signup`)
.send(userData)
.expect(200)
.expect({
data: {
email: userData.email,
firstName: userData.firstName.toLowerCase(),
lastName: userData.lastName.toLowerCase(),
bio: userData.bio,
},
}, done);
});
答案 0 :(得分:1)
您必须手动关闭服务器:
},
}, () => {
app.close()
done()
});
});
答案 1 :(得分:-1)
在所有测试结束之后关闭mongoose连接
afterAll(async (done) => {
await closeMongoConnection();
done();
});
closeMongoConnection:
import mongoose from 'mongoose';
export default () => {
return new Promise((res) => {
res(mongoose.connection.close());
});
};