【发布时间】:2020-10-24 02:23:46
【问题描述】:
如果这是你不应该做的事情,请原谅我,但我已经环顾四周,看看有什么可能。
我想验证我的express 应用是否有一个为该应用调用/使用的中间件。
import express from 'express';
import cors from 'cors';
const app = express();
app.use(cors()); // <----- I WANT TO TEST THIS
app.get('/', (_req, res) => res.send({ hello: 'world' });
app.listen(5000, () => console.log(`Listening on port 5000`));
export default app;
潜力jest测试
import app from './index.ts';
// This is a poor attempt to try and get this to work
test('test if CORS is implemented', () => {
const mockCors = jest.mock('cors');
const myApp = app;
expect(mockCors).toHaveBeenCalledTimes(1);
});
如果有人有解决方案,如果我不应该这样做,背后的原因是什么?
【问题讨论】:
标签: javascript node.js unit-testing express jestjs