茉莉花callFake不适用于快递路由器

时间:2018-07-09 11:40:13

标签: node.js express testing jasmine

我正在使用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();
    })
})

有什么想法吗?

0 个答案:

没有答案