unit testing - Simulating user input for TDD JavaScript -
i'm finding increasingly difficult simulate actual user events using jquery or native element trigger functions. example, if have text input , don't want user able add character, can call e.preventdefault()
jquery-normalised event object on keydown
event. however, there no way programatically verify test scenario.
the following test passes without call preventdefault
because jquery keydown trigger isn't "real" event.
input.val('test').trigger(jquery.event({ which: 68 }); expect(input).tohavevalue('test');
without correct code, test should fail because input should have value of 'testd' (68 character code 'd').
does know methods or libraries simulate real browser ui events?
simulate real event quite complicated. must first determine type of event need , create document.createevent
. call different init*event
initialize event object. finally, use element.dispatchevent
dispatch event target object.
Comments
Post a Comment