Ariya Hidayat 2014-09-03 23:14:31 -07:00
parent c883a80caf
commit 729f12c7d8
4 changed files with 32 additions and 35 deletions

20
test/basics/onerror.js Normal file
View File

@ -0,0 +1,20 @@
var assert = require('../assert');
phantom.onError = undefined;
assert.typeOf(phantom.onError, 'undefined');
var onErrorFunc1 = function() { return !"x"; };
phantom.onError = onErrorFunc1;
asssert.deepEqual(phantom.onError, onErrorFunc1);
var onErrorFunc2 = function() { return !!"y"; };
phantom.onError = onErrorFunc2;
asssert.deepEqual(phantom.onError, onErrorFunc2);
asssert.isTrue(phantom.onError != onErrorFunc1);
// Will only allow setting to a function value, so setting it to `null` returns `undefined`
phantom.onError = null;
assert.typeOf(phantom.onError, 'undefined');
phantom.onError = undefined;
assert.typeOf(phantom.onError, 'undefined');

10
test/basics/stacktrace.js Normal file
View File

@ -0,0 +1,10 @@
var assert = require('../assert');
var stack;
phantom.onError = function(message, s) { stack = s; };
var helperFile = "../fixtures/parse-error-helper.js";
phantom.injectJs(helperFile);
assert.equal(stack[0].file, helperFile);
assert.equal(stack[0].line, 2);

View File

@ -1,35 +0,0 @@
describe("phantom global object", function() {
it("should be able to get the error signal handler that is currently set on it", function() {
phantom.onError = undefined;
expect(phantom.onError).toBeUndefined();
var onErrorFunc1 = function() { return !"x"; };
phantom.onError = onErrorFunc1;
expect(phantom.onError).toEqual(onErrorFunc1);
var onErrorFunc2 = function() { return !!"y"; };
phantom.onError = onErrorFunc2;
expect(phantom.onError).toEqual(onErrorFunc2);
expect(phantom.onError).toNotEqual(onErrorFunc1);
phantom.onError = null;
// Will only allow setting to a function value, so setting it to `null` returns `undefined`
expect(phantom.onError).toBeUndefined();
phantom.onError = undefined;
expect(phantom.onError).toBeUndefined();
});
it("reports parse time error source and line in stack", function() {
var stack;
phantom.onError = function(message, s) { stack = s; };
var helperFile = "./fixtures/parse-error-helper.js";
phantom.injectJs(helperFile);
waits(0);
runs(function() {
expect(stack[0].file).toEqual(helperFile);
expect(stack[0].line).toEqual(2);
phantom.onError = phantom.defaultErrorHandler;
});
});
});

View File

@ -12,6 +12,8 @@ TIMEOUT = 35 # Maximum duration of PhantomJS execution (in seconds)
TESTS = [
'basics/exit.js',
'basics/global.js',
'basics/onerror.js',
'basics/stacktrace.js',
'basics/version.js',
'module/system/system.js',
'module/system/args.js',