Skip to content

Commit

Permalink
added callback to jQueryify
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Aug 12, 2010
1 parent 824a2f3 commit 77275a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 9 additions & 5 deletions lib/jsdom.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ exports.jsdom = function (level) {
exports.createWindow = function (html, level) { exports.createWindow = function (html, level) {
var window = exports.jsdom(level).createWindow(); var window = exports.jsdom(level).createWindow();
window.document.innerHTML = html; window.document.innerHTML = html;

return window; return window;
}; };


exports.jQueryify = function (html, level, path) { exports.jQueryify = function (html, level, path, fn) {
var window = exports.createWindow(html, level); var window = exports.createWindow(html, level);


var head = window.document.getElementsByTagName('head')[0], var head = window.document.getElementsByTagName('head')[0],
jQueryTag = window.document.createElement("script"); jQueryTag = window.document.createElement("script");


path = path ? "file://" + path : 'http://code.jquery.com/jquery-1.4.2.js'; path = path ? "file://" + path : 'http://code.jquery.com/jquery-1.4.2.js';

jQueryTag.src = path; jQueryTag.src = path;

head.appendChild(jQueryTag);


return window; jQueryTag.onload = function() {
if (this.readyState === 'complete') {
if (typeof fn === "function") {
fn();
}
}
};
}; };
14 changes: 12 additions & 2 deletions test/jsdom/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ var sys = require("sys");
exports.tests = { exports.tests = {


build_window : function() { build_window : function() {
sys.debug(sys.inspect(jsdom));
var window = jsdom.jsdom().createWindow(); var window = jsdom.jsdom().createWindow();
assertNotNull("window must be a new object!", window); assertNotNull("window must be a new object!", window);
} },

/*
Async tests and mjsunit dont play well..
jquerify : function() {
var window = jsdom.jQueryify("<html><head></head><body><p>it works</p></body></html>", false, false,
function() {
console.dir(window);
assertEqual("jquery selectors should work at this point", window.jQuery("p").text(), "it works");
});
}*/

}; };

0 comments on commit 77275a8

Please sign in to comment.