当用.tohavebeen调用时,jest模拟函数jest.fn()是否在jest覆盖范围内显示跟踪?

时间:2019-07-09 06:29:59

标签: reactjs jestjs enzyme

如果是!然后我无法使用jest --coverage找到代表其代码行的轨迹,除此之外,我已经使用jest文档进行了模拟函数调用,并且通过了测试,但是没有进行函数调用的跟踪覆盖范围

我尝试过jest.fn()和jest.spyOn函数,并使用浅的,呈现的预定义函数调用酶

必须对其进行呼叫的主页

export default class AddJobOverview extends React.Component {

    constructor(props){
        super(props);

        this.handleNext = this.handleNext.bind(this);
        this.handleChange = this.handleChange.bind(this);



 <NextButton onClick = {this.handleNext} id={"nextButton"}/>
                </MainContainer>
            </div>

测试代码

import React from 'react';
import renderer from 'react-test-renderer';
import AddJobOverview from '../../../Components/Modules/AddJob/AddJobOverview.jsx';
import NextButton from '../../../Components/Modules/AddJob/AddJobOverview.jsx'
import {handleNext} from '../../../Components/Modules/AddJob/AddJobOverview.jsx'
import { shallow, mount, render } from 'enzyme';



describe('AddJobOverview component', () => {

    it('AddJobOverview component renders without crashing', () => {
        shallow(<AddJobOverview/>);

    });


//1st test case
    it('handlenext works Correctly', () => {
        const Fakefun=jest.spyOn(AddJobOverview.prototype,'handleNext');
        const component=shallow((<AddJobOverview/>));

        component.update();
        expect(Fakefun).toHaveBeenCalled();
        done();
    });
//2nd Test case
    it('handlechange works Correctly', () => {
        const handleChange=jest.fn();
        handleChange();
        expect(handleChange).toHaveBeenCalled();
    });


});

因此在上面的代码中,测试1由于一些jest.fn错误而失败了,可以解决!在第二个测试用例中,测试通过了,但是在覆盖率中没有任何痕迹。因此,如何检查测试用例2如果是有效的,那么如何找到跟踪?

0 个答案:

没有答案