February 2019
Beginner
694 pages
18h 4m
English
There will be times when the code you are writing must respond to DOM events, such as onclick or onselect. Luckily, writing tests that need these DOM events can also be simulated by using jQuery, jasmine-jquery, and spies as follows:
describe("click event tests", () => {
it("should trigger an onclick DOM event", () =>{
setFixtures(`
<script>
function handle_my_click_div_clicked() {
// do nothing at this time
}
</script>
<div id='my_click_div'
onclick='handle_my_click_div_clicked()'>Click Here</div>`);
var clickEventSpy = spyOnEvent('#my_click_div', 'click');
$('#my_click_div').click();
expect(clickEventSpy).toHaveBeenTriggered();
});
});
This test is again calling the setFixtures function from the jasmine-jquery library. This ...
Read now
Unlock full access