React 酶测试 - CustomEvent 未定义

问题描述 投票:0回答:1

我一直在测试这个组件,但它输出 CustomEvent is not Defined:下面是我的代码

emitEvent(detail) {
        Utils.setCustomEvent();
        const event = new CustomEvent(detail.eventName, {
            detail,
            bubbles: true,
            cancelable: false,
        });
        document.dispatchEvent(event);
}

Enzyume 测试代码:如何测试 EmitEvent() 中的新 CustomEvent 功能

describe('<ScheduleComp />', () => {
    describe('render ', () => {
        const detail = {
            key: 'productOffering',
            state: 'update',
            eventName: 'data',
            cardName: 'data',
        }
        const wrapper = shallow(<ScheduleComp {...ScheduleCompData} />);
        assert.isNotNull(wrapper);
        it('Should verify if', () => {
            const emitEvent = spy();
            const CustomEvent = spy();

            const component = new ScheduleComp({ ...ScheduleCompData,
                emitEvent,
                CustomEvent
            });

            component.flipCard(event);
            component.emitEvent(detail);
            component.CustomEvent(detail.eventName);
        });

    });
});
reactjs testing enzyme
1个回答
0
投票

进行浅渲染会出现以下错误:

CustomEvent is not defined

您需要使用

render(...)

渲染组件
© www.soinside.com 2019 - 2024. All rights reserved.