javascript - Access the return value of a spied function in Jasmine -
javascript - Access the return value of a spied function in Jasmine -
when spying on function bound event handler keystrokes, how 1 access homecoming value?
here illustration of event handler:
class="snippet-code-js lang-js prettyprint-override">function onkeydown(event) { if (!$(event.target).is("input, textarea, select, *[contenteditable=true]")) { switch (event.keycode) { case 8: // // ... return false; break; case 46: // // ... return false; break; } homecoming true; } }
here illustration of unit test testing it:
class="snippet-code-js lang-js prettyprint-override">describe("myscript.js", function () { var stubs = {}; beforeeach(function() { $(document).bind("keydown.myscript", onkeydown); stubs.myscriptkeydown = spyon(window, "onkeydown").and.callthrough(); }); it("should handle backspace keystrokes", function() { // faked backspace keystroke var event = new $.event("keydown", { keycode: 8 }); $(document).trigger(event); expect(stubs.myscriptkeydown).tohavebeencalled(); }); aftereach(function() { $(document).unbind("keydown.myscript"); }); });
if 1 breaks code, 1 can see homecoming value in function scope in developer tools, there reference available homecoming value of spied function. 1 need assign homecoming value accessible variable in order perform assertion.
being able access homecoming values handy test event handler does/doesn't phone call on other spied helper functions.
do know of way access returned value or improve approach event handling unit tests?
regards
javascript jasmine
Comments
Post a Comment