browser-monkey
Advanced tools
Comparing version 1.17.1 to 1.18.0
21
index.js
@@ -383,4 +383,4 @@ var retry = require('trytryagain'); | ||
var elements = findWithFinder($(selector()), 0); | ||
if (!allowMultiple && elements.length !== 1) { | ||
throw new Error("expected to find exactly one element: " + self.printFinders(self.finders) + ', but found :' + elementsToString(elements)); | ||
if (!allowMultiple) { | ||
expectOneElement(self, elements); | ||
} | ||
@@ -390,2 +390,7 @@ return elements.toArray(); | ||
function expectOneElement(scope, elements) { | ||
var msg = "expected to find exactly one element: " + scope.printFinders(scope.finders) + ', but found :' + elementsToString(elements); | ||
expect(elements.length, msg).to.equal(1); | ||
} | ||
Selector.prototype.resolve = function(options) { | ||
@@ -450,2 +455,14 @@ var self = this; | ||
Selector.prototype.shouldHaveElement = function(fn, options) { | ||
var self = this; | ||
return this.addFinder({ | ||
find: function (elements) { | ||
expectOneElement(self, elements); | ||
elements.toArray().forEach(fn); | ||
return elements; | ||
} | ||
}).shouldExist(options); | ||
}; | ||
Selector.prototype.shouldNotHave = function(options) { | ||
@@ -452,0 +469,0 @@ var resolveOptions = Options.remove(options, ['timeout', 'interval']); |
{ | ||
"name": "browser-monkey", | ||
"version": "1.17.1", | ||
"version": "1.18.0", | ||
"description": "reliable dom testing", | ||
@@ -12,3 +12,2 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "2.2.0", | ||
"chai-as-promised": "5.1.0", | ||
@@ -25,3 +24,3 @@ "karma": "0.12.31", | ||
"dependencies": { | ||
"chai": "3.0.0", | ||
"chai": "dereke/chai", | ||
"debug": "2.2.0", | ||
@@ -28,0 +27,0 @@ "jquery": "2.1.3", |
@@ -271,2 +271,14 @@ # browser monkey | ||
## shouldHaveElement | ||
Assert that there is one element, and that it passes the expectations of a function. | ||
```js | ||
var promise = scope.shouldHaveElement(fn, [options]); | ||
``` | ||
* `fn` a function that tests the element. The function is repeatedly called until it doesn't throw an exception, or until the timeout. | ||
* `options.timeout` the timeout given for the element to pass the expectations, default 1000ms. | ||
* `options.interval` - time between testing the dom (10ms) | ||
## click | ||
@@ -273,0 +285,0 @@ |
@@ -612,18 +612,25 @@ require('lie/polyfill'); | ||
it('eventually finds an element and asserts that it passes a predicate', function () { | ||
var good1 = browser.find('.element').shouldHave({elements: function (elements) { | ||
return $(elements).text() == 'a'; | ||
}}); | ||
var good2 = browser.find('.element').shouldHave(function (elements) { | ||
return $(elements).text() == 'a'; | ||
var good1 = browser.find('.element').shouldHaveElement(function (element) { | ||
expect(element.innerText).to.equal('a'); | ||
}); | ||
var bad1 = browser.find('.element').shouldHave({elements: function (elements) { | ||
return $(elements).text() == 'b'; | ||
}, message: 'expected to have text b'}); | ||
eventuallyInsertHtml('<div class="element"></div><div class="element">a</div>'); | ||
var bad1 = browser.find('.multi').shouldHaveElement(function (element) { | ||
expect(element.innerText).to.equal('b'); | ||
}); | ||
var bad2 = browser.find('.element').shouldHaveElement(function (element) { | ||
expect(element.innerText).to.equal('b'); | ||
}); | ||
var element = $('<div class="element"></div>').appendTo(div); | ||
eventuallyInsertHtml('<div class="multi"></div><div class="multi">b</div>'); | ||
setTimeout(function () { | ||
element.text('a'); | ||
}, 30); | ||
return Promise.all([ | ||
good1, | ||
good2, | ||
expect(bad1).to.be.rejectedWith('expected to have text b') | ||
expect(bad1).to.be.rejectedWith('expected to find exactly one element'), | ||
expect(bad2).to.be.rejectedWith("expected 'a' to equal 'b'") | ||
]); | ||
@@ -630,0 +637,0 @@ }); |
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
62184
9
1307
368
1
1
- Removedassertion-error@1.1.0(transitive)
- Removedchai@3.0.0(transitive)
- Removeddeep-eql@0.1.3(transitive)
- Removedtype-detect@0.1.11.0.0(transitive)
Updatedchai@dereke/chai