jsunit

avoid / capture / verify a Javascript alert when testing a method that displays one with qunit

萝らか妹 提交于 2019-12-09 12:17:19
问题 I'm just starting using Qunit and would like to know whether is there a way to capture/verify/omit alerts, For example: function to_test() { alert("I'm displaying an alert"); return 42; } and then have something like: test("to_test", function() { //in this case I'd like to test the alert. alerts("I'm displaying an alert", to_test(), "to_test() should display an alert"); equals(42, to_test(), "to_test() should return 42" ); // in this case I'd like to omit the alert }); I'm open to the

avoid / capture / verify a Javascript alert when testing a method that displays one with qunit

空扰寡人 提交于 2019-12-03 15:19:12
I'm just starting using Qunit and would like to know whether is there a way to capture/verify/omit alerts, For example: function to_test() { alert("I'm displaying an alert"); return 42; } and then have something like: test("to_test", function() { //in this case I'd like to test the alert. alerts("I'm displaying an alert", to_test(), "to_test() should display an alert"); equals(42, to_test(), "to_test() should return 42" ); // in this case I'd like to omit the alert }); I'm open to the suggestion of using another unit testing tool as well. Thanks in advance! memetech Alright, looks like Sinon