I have almost 100% test coverage, just one last uncovered statement is driving me crazy. It's this event handler for an input event:// Form.class.ts Form.getInputElements().multiply_num.addEventListener('input', (e: Event) => { if (+((e.target as HTMLInputElement).value) > 1) { (options.querySelector('#main-display-add-drink-options-batch') as HTMLElement).style.visibility = 'visible'; } else { (options.querySelector('#main-display-add-drink-options-batch') as HTMLElement).style.visibility = 'hidden'; Form.getInputElements().batch_checkbox.checked = false; } }); Here are the assert statements I expect to pass:// Form.test.ts expect((document.getElementById('main-display-add-drink-options-batch') as HTMLElement).style.visibility).toEqual('hidden'); Form.getInputElements().multiply_num.focus(); Form.getInputElements().multiply_num.dispatchEvent(new KeyboardEvent('keypress', {key: '3'})); expect((document.getElementById('main-display-add-drink-options-batch') as HTMLElement).style.visibility).toEqual('visible'); As you can see I've tried to focus() on the element and then dispatch a keypress event to make the element's value '3' (or is '3' a keyCode?). But, no matter what I do, the final line always fails even though it really shouldn't. What can I explore to solve this and be able to simulate an input event using Jest, /r/node?
Submitted December 03, 2018 at 01:02PM by beefyjon
No comments:
Post a Comment