我正在使用Jasmine
进行测试,并且遇到callFake
的一些问题。
我伪造了fetchPanelRowData
函数,但它仍然进入原始的fetchPanelRowData
。
表达dashboardRouter:
exports.fetchPanelRowData = (req, res) => {
...
}
规格:
const request = require('supertest');
const app = require('../../app');
const dshRouter = require('../../routes/dashboardRouter');
describe('test dashboard router: ', () => {
it('test fetchPanelRowData', async () => {
spyOn(dshRouter, 'fetchPanelRowData').and.callFake((req, res) => {
res.status(500).end();
});
let response = await request(app).post('/api/fetchPanelRowData');
expect(response.statusCode).toBe(500);
expect(dshRouter.fetchPanelRowData).toHaveBeenCalled();
})
})
有什么想法吗?