Answer the question
In order to leave comments, you need to log in
How to simulate a click on an element in Jest (not react)?
My code
describe('Events', () => {
afterEach(() => {
anchor.innerHTML = '';
});
test('click element', () => {
const view = new View(intervalConfig, anchor);
const spy = jest.spyOn(view, 'notify');
const element = anchor.querySelector('.slider__handle') as HTMLElement;
element.dispatchEvent(new Event('click', { bubbles: true }));
expect(spy).toHaveBeenCalled();
spy.mockRestore();
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question