Как издеваться над создателем экшена в шутку - PullRequest
0 голосов
/ 19 февраля 2020

Я хочу проверить этот компонент. где создатель действия вызывает действие из избыточного действия. но когда я пытаюсь вызвать функцию в тестовом файле, она выдает ошибку.

вот мой компонент, который я хочу проверить.

class MyComponent extends Component{

    constructor(props, context){
        super(props, context);
        this.state={
            email: []
        }

        this.myComponentFn = this.myComponentFn.bind(this);
    }

    componentDidMount(){
        this.props.loginActions.getAllComponent(data);
    }


    myComponentFn(requestBody){
        this.props.loginActions.myComponentData(requestBody);
    }

    render(){
        return(
            <div>
                <ToastComponent />
                <MyComponent 
                    myComponentFn = {this.myComponentFn}
                    userDataAuthorities={this.props.userData.authorities}
                />
            </div>
        )
    }
}

const mapStateToProps = (state) => {

    return {

        userData: state.loginReducer.data
    }
};

const mapDispatchToProps = (dispatch) => {

    return {
        loginActions: bindActionCreators(loginActions, dispatch),
       )
    }

};

export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

Вот мой тестовый файл. где я издеваюсь над магазином редуксов. и я попытался вызвать myComponentFn, но произошла ошибка. MyComponent.test.jsx

describe('MyComponent Testing',()=>{

    const initialState = {  };
    const mockStore = configureStore([]);
    const store = mockStore(initialState)
    const myComponentDataMock=jest.fn()

    const wrapper=shallow(<IllustrationManagement myComponentData={myComponentDataMock} store={store}/>, {context: { t: ()=>{
        return "something wrong"
      }}});


        it('should myComponentFn work properly ',()=>{
            const spy = jest.spyOn(wrapper.instance(), "myComponentFn");
            wrapper.instance().myComponentFn(1)
            expect(myComponentDataMock).toHaveBeenCalledTimes(1);
            expect(spy).toHaveBeenCalledTimes(1);
            spy.mockClear()
        });

})

ошибка выброса

Ошибка типа: не удается прочитать свойство _isMockFunction неопределенного

...