browser-monkey
Advanced tools
Comparing version 1.0.0 to 1.1.0
51
index.js
@@ -50,23 +50,48 @@ var retry = require('trytryagain'); | ||
function elementTester(css, options) { | ||
var text = options && options.hasOwnProperty('text')? options.text: undefined; | ||
var ensure = options && options.hasOwnProperty('ensure')? options.ensure: undefined; | ||
var message = options && options.hasOwnProperty('message')? options.message: undefined; | ||
if (typeof css !== 'string') { | ||
options = css; | ||
css = undefined; | ||
} | ||
var cssContains = cssWithText(css, { | ||
text: text | ||
}); | ||
var predicate; | ||
if (typeof options === 'function') { | ||
predicate = options; | ||
options = undefined; | ||
} | ||
var css, text, message; | ||
if (typeof options === 'string') { | ||
css = options; | ||
} else { | ||
css = options && options.hasOwnProperty('css')? options.css: undefined; | ||
text = options && options.hasOwnProperty('text')? options.text: undefined; | ||
message = options && options.hasOwnProperty('message')? options.message: undefined; | ||
} | ||
return { | ||
find: function(element) { | ||
var els = $(element); | ||
if (els.has(cssContains)) { | ||
if (ensure) { | ||
ensure(els); | ||
if (css && !els.is(css)) { | ||
return; | ||
} | ||
if (text) { | ||
var elementText = els.text(); | ||
if (elementText.indexOf(text) < 0) { | ||
throw new Error('expected element to have text ' + JSON.stringify(text) + ' but contained ' + JSON.stringify(elementText)); | ||
} | ||
return els; | ||
} | ||
if (predicate && !predicate(els)) { | ||
return; | ||
} | ||
return els; | ||
}, | ||
toString: function() { | ||
return message || cssContains; | ||
return message || css || text; | ||
} | ||
@@ -179,4 +204,4 @@ }; | ||
Selector.prototype.has = function() { | ||
return this.addFinder(elementTester.apply(null, arguments)); | ||
Selector.prototype.has = function(options) { | ||
return this.addFinder(elementTester(options)).exists(); | ||
}; | ||
@@ -183,0 +208,0 @@ |
@@ -24,3 +24,3 @@ // Karma configuration | ||
exclude: [ | ||
'**/.*.sw?' | ||
'**/*.sw?' | ||
], | ||
@@ -27,0 +27,0 @@ |
{ | ||
"name": "browser-monkey", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "reliable dom testing", | ||
@@ -13,2 +13,3 @@ "main": "index.js", | ||
"chai": "2.2.0", | ||
"chai-as-promised": "5.1.0", | ||
"karma": "0.12.31", | ||
@@ -15,0 +16,0 @@ "karma-browserify": "4.0.0", |
var browser = require('..'); | ||
var expect = require('chai').expect; | ||
var chai = require("chai"); | ||
var expect = chai.expect; | ||
var createTestDiv = require('./createTestDiv'); | ||
var $ = require('jquery'); | ||
var chaiAsPromised = require("chai-as-promised"); | ||
chai.use(chaiAsPromised); | ||
describe('browser-monkey', function () { | ||
@@ -57,2 +61,34 @@ var div; | ||
describe('has', function () { | ||
it('eventually finds an element and asserts that it has text', function () { | ||
var good = browser.find('.element').has({text: 'some t'}); | ||
var bad = browser.find('.element').has({text: 'sme t'}); | ||
setTimeout(function () { | ||
$('<div class="element"><div>some text</div></div>').appendTo(div); | ||
}, 200); | ||
return Promise.all([ | ||
good, | ||
expect(bad).to.be.rejected | ||
]); | ||
}); | ||
it('eventually finds an element and asserts that it has css', function () { | ||
var good = browser.find('.element').has({css: '.the-class'}); | ||
var bad1 = browser.find('.element').has({css: '.not-the-class'}); | ||
var bad2 = browser.find('.element').has({css: '.not-found'}); | ||
setTimeout(function () { | ||
$('<div class="element the-class"><div class="not-the-class">some text</div></div>').appendTo(div); | ||
}, 200); | ||
return Promise.all([ | ||
good, | ||
expect(bad1).to.be.rejected, | ||
expect(bad2).to.be.rejected | ||
]); | ||
}); | ||
}); | ||
it('eventually finds an element containing another element', function () { | ||
@@ -59,0 +95,0 @@ var promise = browser.find('.outer').containing('.inner').exists(); |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
16149
10
463
1
21
9