From c4e9d95420223a245ce043792b3bb31099b69960 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 8 Jan 2013 18:12:56 -0500 Subject: [PATCH] tests.js: Fail if we get a JavaScript error in the page's context (imported from commit 2f1299ff660b8948ac1451e5724c1f198c7a4e29) --- zephyr/tests/frontend/tests.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zephyr/tests/frontend/tests.js b/zephyr/tests/frontend/tests.js index 3d5f14d812..e9b00163d2 100644 --- a/zephyr/tests/frontend/tests.js +++ b/zephyr/tests/frontend/tests.js @@ -120,6 +120,21 @@ function un_narrow() { // Start of test script. casper.start('http://localhost:9981/', function () { + // Fail if we get a JavaScript error in the page's context. + // Based on the example at http://phantomjs.org/release-1.5.html + // + // casper.on('error') doesn't work (it never gets called) so we + // set this at the PhantomJS level. We do it inside 'start' so + // that we know we have a page object. + casper.page.onError = function (msg, trace) { + casper.test.error(msg); + casper.echo('Traceback:'); + trace.forEach(function (item) { + casper.echo(' ' + item.file + ':' + item.line); + }); + casper.exit(1); + }; + casper.test.assertHttpStatus(302); casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/accounts\/home/, 'Redirected to /accounts/home'); casper.click('a[href^="/accounts/login"]');