Я использую Stenciljs и Jest.
Я испытываю трудности с тестированием событий, запускаемых в жизненном цикле (componentDidLoad).
Я могу войти в жизненный цикл, но не могу проверить событие .emit ().
Я пробовал следующее:
.spec.ts
it('should spyOn componentDidLoad', () => {
const component = new App();
jest.spyOn(component, 'componentDidLoad');
let eventSpy = jest.fn();
component.document.addEventListener('toScroll', eventSpy);
expect(component.componentDidLoad()).toHaveBeenCalled();
});
Вот ситуация с первого взгляда:
.tsx
@Event() toScroll: EventEmitter<void>;
componentDidLoad() {
this.toScroll.emit();
}
.spec.ts
it('should spyOn componentDidLoad', () => {
const component = new App();
jest.spyOn(component, 'componentDidLoad');
// need a way to test the emit() here.
expect(component.componentDidLoad()).toHaveBeenCalled();
});
Произошла (логическая) следующая ошибка:
● рендеринг компонента ›должен следить за componentDidLoad
TypeError: Cannot read property 'emit' of undefined