browser-monkey
Advanced tools
Comparing version 1.12.1 to 1.13.0
23
index.js
@@ -91,2 +91,8 @@ var retry = require('trytryagain'); | ||
function elementsToString(els) { | ||
return els.toArray().map(function (el) { | ||
return el.outerHTML.replace(el.innerHTML, ''); | ||
}).join(', '); | ||
} | ||
return { | ||
@@ -98,6 +104,3 @@ find: function(element) { | ||
if (!els.is(css)) { | ||
var elements = els.toArray().map(function (el) { | ||
return el.outerHTML.replace(el.innerHTML, ''); | ||
}); | ||
throw new Error(message || ('expected elements ' + elements.join(', ') + ' to have css ' + css)); | ||
throw new Error(message || ('expected elements ' + elementsToString(els) + ' to have css ' + css)); | ||
} | ||
@@ -120,3 +123,3 @@ } | ||
if (els.length !== length) { | ||
throw new Error(message || ('expected to find ' + length + ' elements but found ' + els.length)); | ||
throw new Error(message || ('expected ' + elementsToString(els) + ' to have ' + length + ' elements')); | ||
} | ||
@@ -172,13 +175,13 @@ } | ||
Selector.prototype.component = function (methods) { | ||
function Extension() { | ||
function Component() { | ||
Selector.apply(this, arguments); | ||
} | ||
Extension.prototype = new this.constructor(); | ||
Component.prototype = new this.constructor(); | ||
Object.keys(methods).forEach(function (method) { | ||
Extension.prototype[method] = methods[method]; | ||
Component.prototype[method] = methods[method]; | ||
}); | ||
Extension.prototype.constructor = Extension; | ||
Component.prototype.constructor = Component; | ||
return new Extension(); | ||
return new Component().scope(this); | ||
}; | ||
@@ -185,0 +188,0 @@ |
{ | ||
"name": "browser-monkey", | ||
"version": "1.12.1", | ||
"version": "1.13.0", | ||
"description": "reliable dom testing", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -471,3 +471,24 @@ var browser = require('..'); | ||
}); | ||
it('components inherit scope', function () { | ||
var adminArea = browser.find('.admin'); | ||
var admin = adminArea.component({ | ||
user: function () { | ||
return this.find('.user'); | ||
} | ||
}); | ||
var promise = admin.user().shouldHave({text: ['Jane']}); | ||
eventuallyInsertHtml( | ||
'<div class="user">Bob</div>' | ||
+ '<div class="admin">' | ||
+ '<div class="user">Jane</div>' | ||
+ '</div>' | ||
); | ||
return promise; | ||
}); | ||
}); | ||
}); |
42668
843