Port a few basic tests of global objects.

https://github.com/ariya/phantomjs/issues/12439
2.0
Ariya Hidayat 2014-09-02 22:28:53 -07:00
parent 3274001e07
commit c883a80caf
4 changed files with 35 additions and 52 deletions

21
test/basics/global.js Normal file
View File

@ -0,0 +1,21 @@
var assert = require('../assert');
assert.typeOf(phantom, 'object');
assert.isTrue(phantom.hasOwnProperty('libraryPath'));
assert.typeOf(phantom.libraryPath, 'string');
assert.isTrue(phantom.libraryPath.length > 0);
assert.isTrue(phantom.hasOwnProperty('outputEncoding'));
assert.typeOf(phantom.outputEncoding, 'string');
assert.equal(phantom.outputEncoding.toLowerCase(), 'utf-8'); // default
assert.isTrue(phantom.hasOwnProperty('injectJs'));
assert.typeOf(phantom.injectJs, 'function');
assert.isTrue(phantom.hasOwnProperty('exit'));
assert.typeOf(phantom.exit, 'function');
assert.isTrue(phantom.hasOwnProperty('cookiesEnabled'));
assert.typeOf(phantom.cookiesEnabled, 'boolean');
assert.isTrue(phantom.cookiesEnabled);

12
test/basics/version.js Normal file
View File

@ -0,0 +1,12 @@
var assert = require('../assert');
assert.isTrue(phantom.hasOwnProperty('version'));
assert.typeOf(phantom.version, 'object');
assert.typeOf(phantom.version.major, 'number');
assert.typeOf(phantom.version.minor, 'number');
assert.typeOf(phantom.version.patch, 'number');
assert.equal(phantom.version.major, 2);
assert.equal(phantom.version.minor, 0);
assert.equal(phantom.version.patch, 0);

View File

@ -1,56 +1,4 @@
describe("phantom global object", function() {
it("should exist", function() {
expect(typeof phantom).toEqual('object');
});
it("should have libraryPath property", function() {
expect(phantom.hasOwnProperty('libraryPath')).toBeTruthy();
});
it("should have libraryPath as a string", function() {
expect(typeof phantom.libraryPath).toEqual('string');
});
it("should not have an empty libraryPath", function() {
expect(phantom.libraryPath.length).toNotEqual(0);
});
it("should have outputEncoding property", function() {
expect(phantom.hasOwnProperty('outputEncoding')).toBeTruthy();
});
it("should have the default outputEncoding of UTF-8", function() {
expect(phantom.outputEncoding.toLowerCase()).toEqual('utf-8');
});
it("should have version property", function() {
expect(phantom.hasOwnProperty('version')).toBeTruthy();
});
it("should return 2 as the major version", function() {
expect(phantom.version.major).toEqual(2);
});
it("should return 0 as the minor version", function() {
expect(phantom.version.minor).toEqual(0);
});
it("should return 0 as the patch version", function() {
expect(phantom.version.patch).toEqual(0);
});
it("should have 'injectJs' function", function() {
expect(typeof phantom.injectJs).toEqual("function");
});
it("should have 'exit' function", function() {
expect(typeof phantom.exit).toEqual("function");
});
it("should have 'cookiesEnabled' property, and should be 'true' by default", function() {
expect(phantom.hasOwnProperty('cookiesEnabled')).toBeTruthy();
expect(phantom.cookiesEnabled).toBeTruthy();
});
it("should be able to get the error signal handler that is currently set on it", function() {
phantom.onError = undefined;

View File

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