tests.js: Fail if we get a JavaScript error in the page's context

(imported from commit 2f1299ff660b8948ac1451e5724c1f198c7a4e29)
This commit is contained in:
Keegan McAllister 2013-01-08 18:12:56 -05:00
parent 4a9d65c758
commit c4e9d95420
1 changed files with 15 additions and 0 deletions

View File

@ -120,6 +120,21 @@ function un_narrow() {
// Start of test script. // Start of test script.
casper.start('http://localhost:9981/', function () { 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.assertHttpStatus(302);
casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/accounts\/home/, 'Redirected to /accounts/home'); casper.test.assertUrlMatch(/^http:\/\/[^\/]+\/accounts\/home/, 'Redirected to /accounts/home');
casper.click('a[href^="/accounts/login"]'); casper.click('a[href^="/accounts/login"]');