Using JEST
to unit test a component that has a keydown listener attached to the document.
How can I test this in JEST
? How do I simulate the keydown event on the document? I need the event listener to be on the document since it is supposed to respond the keyboard action irrespective of the focussed element.
EDIT: The question here is about simulating the event on the document or the document.body. All the examples are regarding an actual DOM node, that works fine but the document does not.
Currently trying to do this:
TestUtils.Simulate.keyDown(document, {keyCode : 37}); // handler not invoked
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…