add spyOnEvent.reset
add
- reset spyOnEvent
- toHaveBeenTriggered
- toHaveBeenPrevented
HTML
<link rel="stylesheet" href="https://raw.github.com/velesin/jasmine-jquery/master/vendor/jasmine/jasmine.css">
<script src="https://raw.github.com/velesin/jasmine-jquery/master/vendor/jasmine/jasmine.js"></script>
<script src="https://raw.github.com/velesin/jasmine-jquery/master/vendor/jasmine/jasmine-html.js"></script>
<script src="https://raw.github.com/yoshi6jp/jasmine-jquery/master/lib/jasmine-jquery.js"></script>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
JavaScript
describe("reset spyOnEvent", function() {
var spyEvent = null;
beforeEach(function() {
setFixtures(sandbox());
spyEvent = spyOnEvent($("#sandbox"), "click");
$("#sandbox").click();
});
it("was clicked", function() {
expect("click").toHaveBeenTriggeredOn($("#sandbox"))
});
describe("reset event", function() {
beforeEach(function() {
spyEvent.reset();
});
it("was clicked", function() {
expect("click").not.toHaveBeenTriggeredOn($("#sandbox"))
});
});
});
describe("toHaveBeenTriggered", function() {
it("was clicked", function() {
setFixtures(sandbox());
var spyEvent = spyOnEvent($("#sandbox"), "click");
expect(spyEvent).not.toHaveBeenTriggered();
$("#sandbox").click();
expect(spyEvent).toHaveBeenTriggered();
expect(spyEvent).not.toHaveBeenPrevented();
});
});
describe("toHaveBeenPrevented", function() {
it("was prevented", function() {
setFixtures(sandbox());
var spyEvent = spyOnEvent($("#sandbox"), "click");
$("#sandbox").on("click", function(e) {
e.preventDefault();
});
$("#sandbox").click();
expect(spyEvent).toHaveBeenPrevented();
});
});