Question · JavaScript and TypeScript course · Module 8: Events and the DOM
Mocking DOM Elements in Tests
Which function of Jest's own API (no extra libraries) do we use to create a mock of the addEventListener method on a DOM element?
Answer options
- element.addEventListener = new Mock()
- jest.fn() assigned to element.addEventListener
- jest.mock('addEventListener')
- element.addEventListener = jest.stub()
You can check the correct answer by solving this task in the CodeWorlds game.