Coding task · JavaScript and TypeScript course · Module 8: Events and the DOM

Exercise: Testing Event Handlers

Complete the tests of a component that handles clicks, written with mock DOM elements and jest.fn().

Task

The index.js file has the DinosaurCardHandler component from the testing lesson, a simple jest.fn() (the mock remembers its calls in mock.calls) and three tests written as functions that return true when the component works correctly. Fill in the blanks: ___BLANK1___ is the event type the constructor should register with addEventListener, ___BLANK2___ is the number of preventDefault() calls after one click, and ___BLANK3___ is the comparison operator that checks that destroy() removes the same function the constructor added. The checker runs your tests on the correct component (they must return true) and on broken versions (they must return false).