dimanche 4 octobre 2020

React Enzyme - How can I test UI component with onEvent Method

Below my React Redux Component Ui code: These Link and Button are ui components which are imported.

<Link
    className="ml-link"
    id="some_id"
    text={'Cancel'}
    onEvent={event => this.ReturnToDashboard(event)}
/>
<Button
    value="NEXT"
    className="next_btn secondary-button"
    id="some_id_1"
    onEvent={event => this.PanelChange(event)}
/>

I tried testing this way:

it('Link/Button OnChange Event', (done) => {
    const Props = {
        value: 'Hello'
    };
    const wrapper = mount(<DrawerFieldSet {...Props} />);
    const link = wrapper.find(Link);
    link.simulate('click', { target: { value: 'Hello' } });
    expect(link.get(0).value).to.equal('Hello');

    done();
});

Aucun commentaire:

Enregistrer un commentaire