Socket
Socket
Sign inDemoInstall

casper-chai

Package Overview
Dependencies
1
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 0.1.6

153

build/casper-chai.js

@@ -1,2 +0,2 @@

/* casper-chai version 0.1.5 */
/* casper-chai version 0.1.6 */

@@ -20,11 +20,6 @@ // -- from: lib/casper-chai.coffee -- \\

casperChai = function(_chai, utils) {
var assert, methods, properties, _addMethod, _addProperty, _exprAsFunction, _matches;
var assert, methods, properties, _addMethod, _addProperty, _exprAsFunction, _get_attrs, _matches;
properties = [];
methods = [];
assert = _chai.assert;
/*
Utilities
---------
*/
_addProperty = function(name, func) {

@@ -36,17 +31,2 @@ return _chai.Assertion.addProperty(name, func);

};
/*
@@@@ _exprAsFunction
Given an expression, turn it in to something that can be
evaluated remotely.
`expr` may be
1. a bare string e.g. "false" or "return true";
2. a function string e.g. "function () { return true }"
3. an actual function e.g. function () { return 'hello' }
*/
_exprAsFunction = function(expr) {

@@ -71,11 +51,2 @@ var fn;

};
/*
@@@@ _matches
Returns true if a `against` matches `value`. The `against` variable
can be a string or regular expression.
If `isEqualFallback` is true then we also try `_.isEqual`.
*/
_matches = function(against, value, isEqualFallback) {

@@ -100,2 +71,19 @@ var regex;

};
_get_attrs = function(selector, attr) {
var attrs, fn;
fn = function(selector, _attr) {
var _casper_attrs, _casper_chai_elements;
_casper_chai_elements = __utils__.findAll(selector);
_casper_attrs = [];
Array.prototype.forEach.call(_casper_chai_elements, function(e) {
return _casper_attrs.push(e.getAttribute(_attr));
});
return _casper_attrs;
};
attrs = casper.evaluate(fn, {
_selector: selector,
_attr: attr
});
return attrs;
};
/*

@@ -109,2 +97,56 @@ Chai Tests

/*
@@@@ attr(attribute_name)
True when the attribute `attribute_name` on `selector` is true.
If the selector matches more than one element with the attribute set, this
will fail. In those cases [attrAll](#attrall) or [attrAny](#attrany).
```javascript
expect("#my_header").to.have.attr('class')
```
*/
_addMethod('attr', function(attr) {
var attr_v, attrs, selector;
selector = this._obj;
attrs = _get_attrs(selector, attr);
assert.equal(attrs.length, 1, "Expected " + selector + " to have one match, but it had " + attrs.length);
attr_v = attrs[0];
return this.assert(attr_v, "Expected selector " + selector + " to have attribute " + attr + ", but it did not", ("Expected selector " + selector + " to not have attribute " + attr + ", ") + ("but it was " + attr_v));
});
/*
@@@@ attrAny(attribute_name)
True when an attribute is set on at least one of the given selectors.
```javascript
expect("div.menu li").to.have.attrAny('selected')
```
*/
_addMethod('attrAny', function(attr) {
var attrs, selector;
selector = this._obj;
attrs = _get_attrs(selector, attr);
return this.assert(_.any(attrs), ("Expected one element matching selector " + selector + " to have attribute") + ("" + attr + " set, but none did"), ("Expected no elements matching selector " + selector + " to have attribute") + ("" + attr + " set, but at least one did"));
});
/*
@@@@ attrAll(attribute_name)
True when an attribute is set on all of the given selectors.
```javascript
expect("div.menu li").to.have.attrAll('class')
```
*/
_addMethod('attrAll', function(attr) {
var attrs, selector;
selector = this._obj;
attrs = _get_attrs(selector, attr);
return this.assert(_.all(attrs), ("Expected all elements matching selector " + selector + " to have attribute") + ("" + attr + " set, but one did not have it"), ("Expected one elements matching selector " + selector + " to not have ") + (" attribute " + attr + " set, but they all had it"));
});
/*
@@@@ fieldValue

@@ -184,5 +226,7 @@

```javascript
expect("return 123").to.matchOnRemote(123)<br/>
expect("return 123").to.matchOnRemote(123)
"typeof jQuery".should.not.matchOnRemote('undefined')
"123.toString()".should.matchOnRemote(/\d+/)
```

@@ -238,2 +282,45 @@

/*
@@@@ tagName
All elements matching the given selector are one of the given tag names.
In other words, given a selector, all tags must be one of the given tags.
Note that those tags need not appear in the selector.
```javascript
".menuItem".has.tagName('li')
"menu li *".has.tagName(['a', 'span'])
```
*/
_addMethod('tagName', function(ok_names) {
var diff, selector, tagnames, _get_tagnames;
selector = this._obj;
if (_.isString(ok_names)) {
ok_names = [ok_names];
} else if (!_.isArray(ok_names)) {
assert.ok(false, "tagName must be a string or list, it was " + typeof ok_names);
}
_get_tagnames = function(selector) {
var fn, _tagnames;
fn = function(selector, _attr) {
var _casper_chai_elements, _casper_tags;
_casper_chai_elements = __utils__.findAll(selector);
_casper_tags = [];
Array.prototype.forEach.call(_casper_chai_elements, function(e) {
return _casper_tags.push(e.tagName.toLowerCase());
});
return _casper_tags;
};
_tagnames = casper.evaluate(fn, {
_selector: selector
});
return _tagnames;
};
tagnames = _get_tagnames(selector);
diff = _.difference(tagnames, ok_names);
return this.assert(diff.length === 0, ("Expected " + selector + " to have only tags " + ok_names + ", but there was") + ("tag(s) " + diff + " appeared"), ("Expected " + selector + " to have tags other than " + ok_names + ", but ") + "those were the only tags that appeared");
});
/*
@@@@ textInDOM

@@ -271,3 +358,3 @@

text = casper.fetchText(selector);
return this.assert(_matches(matcher, text), "expected '" + selector + "' to match " + matcher + ", but it did not", "expected '" + selector + "' to not match " + matcher + ", but it did");
return this.assert(_matches(matcher, text), "expected '" + selector + "' to match " + matcher + ", but it was \"" + text + "\"", "expected '" + selector + "' to not match " + matcher + ", but it did");
});

@@ -274,0 +361,0 @@ /*

@@ -13,28 +13,31 @@ <!--- AUTO-GENERATED BY CAKEFILE. Do not edit! -->

Utilities
---------
#### _exprAsFunction
Chai Tests
----------
Given an expression, turn it in to something that can be
evaluated remotely.
The following are the tests that are added onto Chai Assertion.
#### attr(attribute_name)
`expr` may be
True when the attribute `attribute_name` on `selector` is true.
1. a bare string e.g. "false" or "return true";
If the selector matches more than one element with the attribute set, this
will fail. In those cases [attrAll](#attrall) or [attrAny](#attrany).
2. a function string e.g. "function () { return true }"
3. an actual function e.g. function () { return 'hello' }
#### _matches
```javascript
expect("#my_header").to.have.attr('class')
```
#### attrAny(attribute_name)
Returns true if a `against` matches `value`. The `against` variable
can be a string or regular expression.
True when an attribute is set on at least one of the given selectors.
If `isEqualFallback` is true then we also try `_.isEqual`.
```javascript
expect("div.menu li").to.have.attrAny('selected')
```
#### attrAll(attribute_name)
True when an attribute is set on all of the given selectors.
Chai Tests
----------
The following are the tests that are added onto Chai Assertion.
```javascript
expect("div.menu li").to.have.attrAll('class')
```
#### fieldValue

@@ -79,5 +82,7 @@

```javascript
expect("return 123").to.matchOnRemote(123)<br/>
expect("return 123").to.matchOnRemote(123)
"typeof jQuery".should.not.matchOnRemote('undefined')
"123.toString()".should.matchOnRemote(/\d+/)
```

@@ -105,2 +110,14 @@

```
#### tagName
All elements matching the given selector are one of the given tag names.
In other words, given a selector, all tags must be one of the given tags.
Note that those tags need not appear in the selector.
```javascript
".menuItem".has.tagName('li')
"menu li *".has.tagName(['a', 'span'])
```
#### textInDOM

@@ -107,0 +124,0 @@

@@ -1,1 +0,1 @@

(function(){var t;t=function(t,e){var i,s,r,n,o,u,c;r=[];s=[];i=t.assert;o=function(e,i){return t.Assertion.addProperty(e,i)};n=function(e,i){return t.Assertion.addMethod(e,i)};u=function(t){var e;if(_.isFunction(t)){e=t}else if(_.isString(t)){if(/^\s*function\s+/.test(t)){e=t}else{if(t.indexOf("return ")===-1){e="function () { return "+t+" }"}else{e="function () { "+t+" }"}}}else{this.assert(false,"Expression "+t+" must be a function, or a string")}return e};c=function(t,e,i){var s;if(i==null){i=false}if(typeof t==="string"){s=new RegExp("^"+t+"$")}else if(_.isRegExp(t)){s=t}else if(i){if(toString.call(e)==="[object RuntimeArray]"){e=_.toArray(e)}return _.isEqual(t,e)}else{throw new Error("Test received "+t+", but expected string",+" or regular expression.")}return s.test(e)};n("fieldValue",function(t){var e,i,s;s=this._obj;if(_.isString(s)){}else{expect(s).to.be.inDOM}e=function(t){return __utils__.getFieldValue(t)};i=casper.evaluate(e,{selector:s});return this.assert(i===t,"expected field(s) "+s+" to have value "+t+", "+("but it was "+i),"expected field(s) "+s+" to not have value "+t+", "+"but it was")});o("inDOM",function(){var t;t=this._obj;return this.assert(casper.exists(t),"expected selector #{this} to be in the DOM, but it was not","expected selector #{this} to not be in the DOM, but it was")});o("loaded",function(){var t;t=this._obj;return this.assert(casper.resourceExists(t),"expected resource #{this} to exist, but it does not","expected resource #{this} to not exist, but it does")});n("matchOnRemote",function(t){var e,i,s;e=this._obj;i=u(e);s=casper.evaluate(i);return this.assert(c(t,s,true),"expected "+this._obj+" ("+i+" = "+s+") to match "+t,"expected "+this._obj+" ("+i+") to not match "+t+", but it did")});o("matchTitle",function(){var t,e;t=this._obj;e=casper.getTitle();return this.assert(c(t,e),"expected title #{this} to match #{exp}, but it did not","expected title #{this} to not match #{exp}, but it did")});o("matchCurrentUrl",function(){var t,e;e=this._obj;t=casper.getCurrentUrl();return this.assert(c(e,t),"expected url #{exp} to match #{this}, but it did not","expected url #{exp} to not match #{this}, but it did")});o("textInDOM",function(){var t,e;e=this._obj;t=casper.evaluate(function(){return document.body.textContent||document.body.innerText});return this.assert(t.indexOf(e)!==-1,"expected text #{this} to be in the document, but it was not","expected text #{this} to not be in the document, but it was found")});n("textMatch",function(t){var e,i;e=this._obj;i=casper.fetchText(e);return this.assert(c(t,i),"expected '"+e+"' to match "+t+", but it did not","expected '"+e+"' to not match "+t+", but it did")});o("trueOnRemote",function(){var t,e,i;t=this._obj;e=u(t);i=casper.evaluate(e);return this.assert(i,"expected expression "+this._obj+" to be true, but it was "+i,"expected expression "+this._obj+" to not be true, but itw as "+i)});return o("visible",function(){var t;t=this._obj;expect(t).to.be.inDOM;return this.assert(casper.visible(t),"expected selector #{this} to be visible, but it was not","expected selector #{this} to not be, but it was")})};if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){module.exports=t}else if(typeof define==="function"&&define.amd){define(function(){return t})}else{chai.use(t)}}).call(this);
(function(){var t;t=function(t,e){var r,i,s,n,o,a,u,c;s=[];i=[];r=t.assert;o=function(e,r){return t.Assertion.addProperty(e,r)};n=function(e,r){return t.Assertion.addMethod(e,r)};a=function(t){var e;if(_.isFunction(t)){e=t}else if(_.isString(t)){if(/^\s*function\s+/.test(t)){e=t}else{if(t.indexOf("return ")===-1){e="function () { return "+t+" }"}else{e="function () { "+t+" }"}}}else{this.assert(false,"Expression "+t+" must be a function, or a string")}return e};c=function(t,e,r){var i;if(r==null){r=false}if(typeof t==="string"){i=new RegExp("^"+t+"$")}else if(_.isRegExp(t)){i=t}else if(r){if(toString.call(e)==="[object RuntimeArray]"){e=_.toArray(e)}return _.isEqual(t,e)}else{throw new Error("Test received "+t+", but expected string",+" or regular expression.")}return i.test(e)};u=function(t,e){var r,i;i=function(t,e){var r,i;i=__utils__.findAll(t);r=[];Array.prototype.forEach.call(i,function(t){return r.push(t.getAttribute(e))});return r};r=casper.evaluate(i,{_selector:t,_attr:e});return r};n("attr",function(t){var e,i,s;s=this._obj;i=u(s,t);r.equal(i.length,1,"Expected "+s+" to have one match, but it had "+i.length);e=i[0];return this.assert(e,"Expected selector "+s+" to have attribute "+t+", but it did not","Expected selector "+s+" to not have attribute "+t+", "+("but it was "+e))});n("attrAny",function(t){var e,r;r=this._obj;e=u(r,t);return this.assert(_.any(e),"Expected one element matching selector "+r+" to have attribute"+(""+t+" set, but none did"),"Expected no elements matching selector "+r+" to have attribute"+(""+t+" set, but at least one did"))});n("attrAll",function(t){var e,r;r=this._obj;e=u(r,t);return this.assert(_.all(e),"Expected all elements matching selector "+r+" to have attribute"+(""+t+" set, but one did not have it"),"Expected one elements matching selector "+r+" to not have "+(" attribute "+t+" set, but they all had it"))});n("fieldValue",function(t){var e,r,i;i=this._obj;if(_.isString(i)){}else{expect(i).to.be.inDOM}e=function(t){return __utils__.getFieldValue(t)};r=casper.evaluate(e,{selector:i});return this.assert(r===t,"expected field(s) "+i+" to have value "+t+", "+("but it was "+r),"expected field(s) "+i+" to not have value "+t+", "+"but it was")});o("inDOM",function(){var t;t=this._obj;return this.assert(casper.exists(t),"expected selector #{this} to be in the DOM, but it was not","expected selector #{this} to not be in the DOM, but it was")});o("loaded",function(){var t;t=this._obj;return this.assert(casper.resourceExists(t),"expected resource #{this} to exist, but it does not","expected resource #{this} to not exist, but it does")});n("matchOnRemote",function(t){var e,r,i;e=this._obj;r=a(e);i=casper.evaluate(r);return this.assert(c(t,i,true),"expected "+this._obj+" ("+r+" = "+i+") to match "+t,"expected "+this._obj+" ("+r+") to not match "+t+", but it did")});o("matchTitle",function(){var t,e;t=this._obj;e=casper.getTitle();return this.assert(c(t,e),"expected title #{this} to match #{exp}, but it did not","expected title #{this} to not match #{exp}, but it did")});o("matchCurrentUrl",function(){var t,e;e=this._obj;t=casper.getCurrentUrl();return this.assert(c(e,t),"expected url #{exp} to match #{this}, but it did not","expected url #{exp} to not match #{this}, but it did")});n("tagName",function(t){var e,i,s,n;i=this._obj;if(_.isString(t)){t=[t]}else if(!_.isArray(t)){r.ok(false,"tagName must be a string or list, it was "+typeof t)}n=function(t){var e,r;e=function(t,e){var r,i;r=__utils__.findAll(t);i=[];Array.prototype.forEach.call(r,function(t){return i.push(t.tagName.toLowerCase())});return i};r=casper.evaluate(e,{_selector:t});return r};s=n(i);e=_.difference(s,t);return this.assert(e.length===0,"Expected "+i+" to have only tags "+t+", but there was"+("tag(s) "+e+" appeared"),"Expected "+i+" to have tags other than "+t+", but "+"those were the only tags that appeared")});o("textInDOM",function(){var t,e;e=this._obj;t=casper.evaluate(function(){return document.body.textContent||document.body.innerText});return this.assert(t.indexOf(e)!==-1,"expected text #{this} to be in the document, but it was not","expected text #{this} to not be in the document, but it was found")});n("textMatch",function(t){var e,r;e=this._obj;r=casper.fetchText(e);return this.assert(c(t,r),"expected '"+e+"' to match "+t+', but it was "'+r+'"',"expected '"+e+"' to not match "+t+", but it did")});o("trueOnRemote",function(){var t,e,r;t=this._obj;e=a(t);r=casper.evaluate(e);return this.assert(r,"expected expression "+this._obj+" to be true, but it was "+r,"expected expression "+this._obj+" to not be true, but itw as "+r)});return o("visible",function(){var t;t=this._obj;expect(t).to.be.inDOM;return this.assert(casper.visible(t),"expected selector #{this} to be visible, but it was not","expected selector #{this} to not be, but it was")})};if(typeof require==="function"&&typeof exports==="object"&&typeof module==="object"){module.exports=t}else if(typeof define==="function"&&define.amd){define(function(){return t})}else{chai.use(t)}}).call(this);

@@ -10,3 +10,3 @@ {

],
"version": "0.1.5",
"version": "0.1.6",
"author": "Brian M Hunt <brianmhunt@gmail.com>",

@@ -13,0 +13,0 @@ "license": "MIT",

@@ -32,2 +32,17 @@ # Casper.JS Assertions for Chai [![Build Status](https://secure.travis-ci.org/brianmhunt/casper-chai.png?branch=master)](https://travis-ci.org/brianmhunt/casper-chai)

<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attr'>attr(attr_name)</a></td>
<td>True when one selector has the given attribute
</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attrany'>attrAny(attr_name)</a></td>
<td>True when any selector has the given attribute
</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attrall'>attrAll(attr_name)</a></td>
<td>True when all elements matching selector have the given attribute
</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#fieldvalue'>fieldValue(value)</a></td>

@@ -59,2 +74,6 @@ <td>

<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#tagname'>tagName(valid_tags)</a></td>
<td>all elements matching the selectors are one of the given tags</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#textindom'>textInDOM</a></td>

@@ -64,3 +83,3 @@ <td>the text can be found in the DOM</td>

<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#textmatch)'>textMatch(expression)</a></td>
<td><a href='casper-chai/blob/master/build/casper-chai.md#textmatch'>textMatch(expression)</a></td>
<td>

@@ -67,0 +86,0 @@ the text of the given selector matches the expression (a string

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc