Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-monkey

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-monkey - npm Package Compare versions

Comparing version 2.0.0 to 2.2.0

5

actions.js

@@ -45,2 +45,7 @@ var debug = require('debug')('browser-monkey');

select: function(options) {
if (typeof options == 'string') {
var o = arguments[1] || {};
o.text = options;
return this.select(o);
}
var $ = this.get('$');

@@ -47,0 +52,0 @@ var self = this;

@@ -21,2 +21,7 @@ var Options = require('./options');

shouldFind: function (selector, findOptions, existOptions) {
return this.find(selector, findOptions)
.shouldExist(existOptions)
},
shouldNotExist: function (options) {

@@ -23,0 +28,0 @@ return this.notResolve(options)

19

elementTester.js

@@ -115,7 +115,18 @@ var chai = require('chai');

elements.forEach(function(el){
Object.keys(attributes).forEach(function(attributeKey){
expect($(el).attr(attributeKey)).to.equal(attributes[attributeKey]);
if (attributes instanceof Array) {
expect(elements.length).to.equal(attributes.length, 'expected the matched elements to be the same length as the expected attributes')
elements.forEach(function(el, index){
var attributesForElement = attributes[index];
Object.keys(attributesForElement).forEach(function(attributeKey){
expect($(el).attr(attributeKey)).to.equal(attributesForElement[attributeKey]);
});
});
});
} else {
elements.forEach(function(el){
Object.keys(attributes).forEach(function(attributeKey){
expect($(el).attr(attributeKey)).to.equal(attributes[attributeKey]);
});
});
}
},

@@ -122,0 +133,0 @@

{
"name": "browser-monkey",
"version": "2.0.0",
"version": "2.2.0",
"description": "reliable dom testing",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -239,3 +239,3 @@ # browser monkey [![npm version](https://img.shields.io/npm/v/browser-monkey.svg)](https://www.npmjs.com/package/browser-monkey) [![npm](https://img.shields.io/npm/dm/browser-monkey.svg)](https://www.npmjs.com/package/browser-monkey) [![Build Status](https://travis-ci.org/featurist/browser-monkey.svg?branch=master)](https://travis-ci.org/featurist/browser-monkey)

```js
var promise = scope.shouldExist([options]);
var promise = browser.find('.selector').shouldExist([options]);
```

@@ -249,2 +249,10 @@

## shouldFind
As an alternative to `browser.find('.selector').shouldExist()` you can also do:
```js
browser.shouldFind('.selector')
````
## shouldNotExist

@@ -332,2 +340,18 @@

```js
browser.find('img').shouldHave({
attributes: [
{src: '/monkey1.jpg', alt: 'first monkey'},
{src: '/monkey2.jpg', alt: 'second monkey'},
]
})
```
would match:
```html
<img src="/monkey1.jpg" alt="first monkey">
<img src="/monkey2.jpg" alt="second monkey">
```
* `options.text` - a string, expects the resolved scope to contain the text. If an array of strings, expects the elements to have the same number of elements as there are strings in the array, and expects each string to be found in each respective element's text.

@@ -342,3 +366,3 @@ * `options.exactText` - a string, expects the resolved scope to have the exact text. If an array of strings, expects the elements to have the same number of elements as there are strings in the array, and expects each string to equal each respective element's text.

* `options.elements` - a function, which is passed the resolved elements, return truthy for a match, falsey for a failure.
* `options.attributes` - an object representing the attributes that should appear on an element, `shouldHave({ attributes: { href: '/home' } })` would match `<a href="/home"></a>`
* `options.attributes` - an object or an array of objects representing the attributes that should appear on one or more elements, `shouldHave({ attributes: { href: '/home' } })` would match `<a href="/home"></a>`
* `options.message` - the error message

@@ -406,6 +430,11 @@ * `options.timeout` - length of time to wait for the element (1000ms)

```js
scope.select({text: 'Text of option'}).then(function () {
});
scope.select({text: 'Text of option'})
```
or
```js
scope.select('Text of option')
```
Example:

@@ -436,2 +465,3 @@

* `options.text` - a string, text to match against the options text, this will also match partial text
* `options` could also just be the text of the string to match

@@ -438,0 +468,0 @@ ## fill

@@ -122,3 +122,13 @@ var domTest = require('./domTest');

domTest('should eventually select an option element using the text', function(browser, dom, $){
domTest('respects timeout option, when passed separately from text', function(browser, dom, $){
var promise = browser.find('.element').select('Second', {timeout: 3 });
dom.eventuallyInsert(
$('<select class="element"><option>First</option><option>Second</option></select>')
, 6);
return expect(promise).to.be.rejectedWith('expected to find: .element select option {"timeout":3,"text":"Second"}');
});
domTest('eventually selects an option element using the text', function(browser, dom, $){
var promise = browser.find('.element').select({text: 'Second'});

@@ -138,2 +148,17 @@ var selectedItem = undefined;

domTest('eventually selects an option element using the text, when text is passed as a string', function(browser, dom, $){
var promise = browser.find('.element').select('Second');
var selectedItem = undefined;
dom.eventuallyInsert(
$('<select class="element"><option>First</option><option>Second</option></select>').on('change', function () {
selectedItem = $(this).find('option[selected]').text();
})
);
return promise.then(function () {
expect(selectedItem).to.equal('Second');
});
});
domTest('should eventually select an option element using a partial match', function(browser, dom, $){

@@ -140,0 +165,0 @@ var promise = browser.find('.element').select({text: 'Seco'});

@@ -56,2 +56,12 @@ var domTest = require('./domTest');

describe('shouldFind', function(){
domTest('stack trace', function(browser, dom){
return browser
.shouldFind('div')
.assertStackTrace(__filename);
}, {
mochaOnly: true
});
});
describe('is', function () {

@@ -259,2 +269,24 @@ domTest('should eventually find an element if it has a class', function (browser, dom) {

domTest('verifies array of attributes are present', function(browser, dom){
dom.insert('<div><img src="/a"/><img src="/b"/><img src="/c"/></div>');
var good = browser.find('img').shouldHave({
attributes: [
{src: '/a'},
{src: '/b'},
{src: '/c'},
]
});
var bad = browser.find('img').shouldHave({
attributes: [
{src: '/c'},
{src: '/a'},
{src: '/b'},
]
});
return Promise.all([
good,
expect(bad).to.be.rejected
]);
});
describe('exactText', function(){

@@ -261,0 +293,0 @@ domTest('eventually finds elements that have the exact array of text', function(browser, dom){

@@ -12,2 +12,10 @@ var domTest = require('./domTest');

domTest('should eventually find an element, when collapsed into shouldFind(selector)', function (browser, dom) {
var promise = browser.shouldFind('.element');
dom.eventuallyInsert('<div class="element"></div>');
return promise;
});
domTest('should eventually find an element using a filter', function (browser, dom) {

@@ -14,0 +22,0 @@ var promise = browser.find('.element').filter(function (element) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc