'Dispatch InputEvent in test

I have a simple test that I want to see that my React component is handling an input event. So far I have

it("changes value when onChange is fired", () => {

      const onChange = jest.fn();
      act(() => {
        render(<DateInput value={'2020-05-24'} onChange={onChange} />, container);
      });
    
        // get a hold of the button element, and trigger some clicks on it
        const input = container.querySelector("input");
        expect(input.value).toBe("2020-05-24");
    
        act(() => {
          input.dispatchEvent(new InputEvent("change", "2020-05-25"));
        });
        expect(onChange).toHaveBeenCalledTimes(1);
    });

The problem is that I get an error that

ReferenceError: InputEvent is not defined

How do I fire an onChange event in a test?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source