I\'m trying to simulate a keyDown
event, specifically for Enter, keyCode: 13
. I\'ve tried a number of different ways of doing this, but none of them ar
If you try to simulate a Event while shallowing an Element you could mock the document.addEventListener
method:
let events = [];
document.addEventListener = jest.fn((event, cb) => {
events[event] = cb;
});
shallow( );
// trigger the keypress event
events.keyup({key: 's'});
// your test expectations
expect(someMethod).toBeCalledTimes(1);