用反应酶断言道具功能值时的错误功能

时间:2018-06-01 21:45:34

标签: reactjs jestjs enzyme

我有以下测试,我使用酶来测试onLoad props函数在componentDidMount上执行的事实。但是,当我运行测试时,我得到以下 “TypeError:this.props.onLoad不是函数”

import React from 'react';
import {
    shallow,
    mount
} from 'enzyme'
import App from './App';
import { spy } from ''
import Category from './Category'
it('loads the list of categories', () => {
    const spy = jest.spyOn(Category.prototype, 'componentDidMount');
    const onLoadMock = jest.fn();
    const component = mount(<Category onLoad={onLoadMock}/>);
    expect(component.props().onLoad).toEqual(onLoadMock);
    expect(onLoadMock).toHaveBeenCalledTimes(1);  
});
import React, { Component } from 'react';

class Category extends Component{
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.props.onLoad();
    }

    render() {
        return (
            <ol className="list-container">
            </ol>
        );
    }
}

出口默认类别;      在Category.componentDidMount(src / components / Category.js:9:20) “有人帮我解决了什么问题吗?

0 个答案:

没有答案