我一直在测试这个组件,但它输出 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);
});
});
});
进行浅渲染会出现以下错误:
CustomEvent is not defined
您需要使用
render(...)
渲染组件