Skip to content

Commit

Permalink
now with jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Oct 29, 2011
1 parent 44867f3 commit a6de2c8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
9 changes: 3 additions & 6 deletions example/form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var test = require('testling');

test('login', function (t) {
t.createWindow('http://localhost:8081', function (win) {
t.createWindow('http://localhost:8081', function (win, $) {
var pending = 2;
function finish () {
if (--pending === 0) t.end();
Expand All @@ -14,11 +14,8 @@ test('login', function (t) {
finish();
});

for (var i = 0; i < form.elements.length; i++) {
var elem = form.elements[i];
if (elem.name === 'user') elem.value = 'abc';
if (elem.name === 'pass') elem.value = 'def';
}
$('input[name=user]', form).val('abc');
$('input[name=pass]', form).val('def');

t.submitForm(form, function (w) {
t.equal(w.document.body.innerHTML, 'welcome!');
Expand Down
2 changes: 1 addition & 1 deletion lib/output/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Handler.prototype.end = function (res) {
this.writeBrowser(key);
this.write('\r\n');

this.fails[key].forEach(function (xs) {
(this.fails[key] || []).forEach(function (xs) {
function str (x) {
return JSON.stringify(x);
}
Expand Down
18 changes: 15 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ Test.prototype.end = function () {
};

var jsdom = require('jsdom');
var fs = require('fs');
var emptyHtml = '<html><head></head><body></body></html>';

var jqueryWin = jsdom.jsdom(
'<html><head><script>'
+ fs.readFileSync(__dirname + '/../vendor/jquery-1.6.min.js', 'utf8')
+ '</script></head><body></body></html>'
).createWindow();

Test.prototype.createWindow = function (url, opts, cb) {
if (typeof url === 'object') {
Expand Down Expand Up @@ -346,19 +354,23 @@ function createWindow (self, opts, cb) {
;
}

var html = '<html><head></head><body></body></html>';
var doc = jsdom.jsdom(html, '3', {
var doc = jsdom.jsdom(emptyHtml, '3', {
deferClose : true,
url : opts.url
});

var win = doc.createWindow();

win.addEventListener('load', function () {
var ts = doc.getElementsByTagName('title');
if (ts.length) doc.title = ts[0] && ts[0].textContent || '';

try {
cb(win);
cb(win, function (x, y) {
return y === undefined
? jqueryWin.$(x, doc)
: jqueryWin.$(x, y)
});
}
catch (err) {
self.assert({
Expand Down
16 changes: 16 additions & 0 deletions vendor/jquery-1.6.min.js

Large diffs are not rendered by default.

0 comments on commit a6de2c8

Please sign in to comment.