From adcb14dd0e01d3a84c2e8218f7103ba172d78f7a Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 18 Mar 2012 22:35:43 +0000 Subject: [PATCH] Basic tests for the onError handler http://code.google.com/p/phantomjs/issues/detail?id=166 --- test/webpage-spec.js | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/webpage-spec.js b/test/webpage-spec.js index 8e46d77a..97a46ce9 100644 --- a/test/webpage-spec.js +++ b/test/webpage-spec.js @@ -229,6 +229,52 @@ describe("WebPage object", function() { expect(page.evaluate(function () { return window.navigator.plugins.length })).toEqual(0); }); }); + + it("reports unhandled errors", function() { + var hadError = false; + + runs(function() { + page = new require('webpage').create(); + page.onError = function() { hadError = true }; + page.evaluate(function() { + setTimeout(function() { referenceError }, 0) + }); + }); + + waits(0); + + runs(function() { + expect(hadError).toEqual(true); + }); + }) + + it("doesn't report handled errors", function() { + var hadError = false; + var caughtError = false; + + page = new require('webpage').create(); + + runs(function() { + page.onError = function() { hadError = true }; + page.evaluate(function() { + caughtError = false; + setTimeout(function() { + try { + referenceError + } catch(e) { + caughtError = true; + } + }, 0) + }); + }); + + waits(0); + + runs(function() { + expect(hadError).toEqual(false); + expect(page.evaluate(function() { return caughtError })).toEqual(true); + }); + }) }); describe("WebPage construction with options", function () {