var jsdom = require('../../lib/jsdom'), path = require('path') jQueryPath = path.resolve(__dirname, '../jquery-fixtures/jquery-1.4.2.js'); exports.tests = { scripts_share_a_global_context: function(test) { var window = jsdom.jsdom('\ \ \ \ \ ' ).createWindow(); test.equal(window.confirmTheLocalIsOnTheWindow, window.localOnWindow, 'local variables should be attached to the window'); test.equal(window.hello, "hello world", 'window should be the global context'); test.equal(window.bye, "goodbye", 'window should be the global context'); test.equal(window.abc, 123, 'local vars should not leak out to the window'); test.strictEqual(window.hidden, undefined, 'vars in a closure are safe'); test.equal(window.exposed, 'hidden', 'vars exposed to the window are global'); test.equal(window.imOnAWindow, true, 'setting this in the outer context should apply to the window'); test.equal(window.object.a, 1, 'prototypes should be maintained across contexts'); test.done(); }, scripts_jquerify_have_jsdom_class: function(test) { var window = jsdom.jsdom().createWindow(); jsdom.jQueryify(window, [jQueryPath] , function(dom) { test.ok(dom.window.$('script').hasClass("jsdom")); test.done(); }); }, scripts_env_have_jsdom_class: function(test) { var htmlString = ''; jsdom.env(htmlString, [jQueryPath] , function(error, dom) { test.ok(dom.window.$('script').hasClass("jsdom")); test.done(); }); }, global_is_window_in_scripts: function(test){ var window = jsdom.jsdom('\ \ ').createWindow(); test.strictEqual(window.results[0], true, "window should equal global this"); test.strictEqual(window.results[1], true, "window should equal this.window"); test.strictEqual(window.results[2], true, "this should equal window.window"); test.strictEqual(window.results[3], true, "this should equal document.parentWindow"); test.strictEqual(window.document.parentWindow, window, "outside window context, document.parentWindow should be window as well"); test.done(); }, global_in_object_should_be_valid_in_other_scripts: function(test){ var window = jsdom.jsdom('\ \ \ ').createWindow(); test.strictEqual(window.appVersion, process.version); test.done(); }, window_functions: function(test){ var window = jsdom.jsdom('\ \ ').createWindow(); test.strictEqual(window.DONE, 1); test.done(); }, script_execution_in_body : function(test) { var window, caught = false; var html = '\ '; test.doesNotThrow(function() { jsdom.jsdom(html).createWindow(); }) test.done(); }, // see: https://github.com/tmpvar/jsdom/issues/163 issue_163 : function(test) { jsdom.env('', [__dirname + '/files/163.js'], function(errors, window) { test.ok(!errors, 'no errors'); test.ok(window.hasNativeObjects === true, 'window has the expected properties'); test.done(); }); }, // see: https://github.com/tmpvar/jsdom/issues/179 issue_179 : function(test) { jsdom.env('', [__dirname + '/files/179.js'], function(errors, window) { test.ok(!errors, 'no errors'); test.ok(window.b === 42, 'local var gets hung off of the window'); test.ok(window.exposed === 42, 'read local var from window and exposed it'); test.done(); }); }, timer_executes_in_context : function (test) { jsdom.env('', [__dirname + '/files/timer_in_context.js'], function (errors, window) { setTimeout(function () { test.ok(window.x == 1); test.done(); }, 1); }); } };