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.3 to 0.1.4

161

build/casper-chai.js

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

/* casper-chai version 0.1.4 */

@@ -18,17 +19,11 @@ // -- from: lib/casper-chai.coffee -- \\

casperChai = function(_chai, utils) {
var methods, properties, _addMethod, _addProperty, _matches;
var assert, methods, properties, _addMethod, _addProperty, _exprAsFunction, _matches;
properties = [];
methods = [];
_matches = function(string_or_regex, value) {
var regex;
if (typeof string_or_regex === 'string') {
regex = new RegExp("^" + string_or_regex + "$");
} else if (_.isRegExp(string_or_regex)) {
regex = string_or_regex;
} else {
throw new Error("Test received " + string_or_regex + ", but expected string", +" or regular expression.");
}
return regex.test(value);
};
assert.casper = {};
assert = _chai.assert;
/*
Utilities
---------
*/
_addProperty = function(name, func) {

@@ -40,2 +35,80 @@ return _chai.Assertion.addProperty(name, func);

};
/*
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) {
var fn;
if (_.isFunction(expr)) {
fn = expr;
} else if (_.isString(expr)) {
if (/^\s*function\s+/.test(expr)) {
fn = expr;
} else {
if (expr.indexOf('return ') === -1) {
fn = "function () { return " + expr + " }";
} else {
fn = "function () { " + expr + " }";
}
}
} else {
this.assert(false, "Expression " + expr + " must be a function, or a string");
}
return fn;
};
/*
Returns true if a given string_or_regex matches the given value
*/
_matches = function(against, value) {
var regex;
if (typeof against === 'string') {
regex = new RegExp("^" + against + "$");
} else if (_.isRegExp(against)) {
regex = against;
} else {
return _.isEqual(against, value);
throw new Error("Test received " + against + ", but expected string", +" or regular expression.");
}
return regex.test(value);
};
/*
Chai Tests
----------
The following are the tests that are added onto Chai Assertion.
*/
/*
fieldValue
~~~~~~~~~~
Wraps the __utils__.getFieldValue(selector)
*/
_addMethod('fieldValue', function(givenValue) {
var get_remote_value, remoteValue, selector;
selector = this._obj;
if (_.isString(selector)) {
} else {
expect(selector).to.be.inDOM;
}
get_remote_value = function(selector) {
return __utils__.getFieldValue(selector);
};
remoteValue = casper.evaluate(get_remote_value, {
selector: selector
});
return this.assert(remoteValue === givenValue, ("expected field(s) " + selector + " to have value " + givenValue + ", ") + ("but it was " + remoteValue), ("expected field(s) " + selector + " to not have value " + givenValue + ", ") + "but it was");
});
_addProperty('inDOM', function() {

@@ -46,8 +119,2 @@ var selector;

});
_addProperty('visible', function() {
var selector;
selector = this._obj;
expect(selector).to.be.inDOM;
return this.assert(casper.visible(selector), 'expected selector #{this} to be visible, but it was not', 'expected selector #{this} to not be, but it was');
});
_addProperty('loaded', function() {

@@ -58,2 +125,14 @@ var resourceTest;

});
/*
matchOnRemote
~~~~~~~~~~~~~~
*/
_addMethod('matchOnRemote', function(matcher) {
var expr, fn, remoteValue;
expr = this._obj;
fn = _exprAsFunction(expr);
remoteValue = casper.evaluate(fn);
return this.assert(_matches(matcher, remoteValue), "expected " + this._obj + " (" + fn + " = " + remoteValue + ") to match " + matcher, "expected " + this._obj + " (" + fn + ") to not match " + matcher + ", but it did");
});
_addProperty('matchTitle', function() {

@@ -85,18 +164,34 @@ var matcher, title;

});
return _addMethod('fieldValue', function(givenValue) {
var get_remote_value, remoteValue, selector;
selector = this._obj;
if (_.isString(selector)) {
/*
trueOnRemote
~~~~~~~~~~~~
This assertion passes when the given expression is true on the remote.
For example:
"true".should.be.trueOnRemote
or
(function() { return false }).should.not.be.trueOnRemote
or
expect("function () { return true }").to.be.trueOnRemote
*/
} else {
expect(selector).to.be.inDOM;
}
get_remote_value = function(selector) {
return __utils__.getFieldValue(selector);
};
remoteValue = casper.evaluate(get_remote_value, {
selector: selector
});
return this.assert(remoteValue === givenValue, ("expected field(s) " + selector + " to have value " + givenValue + ", ") + ("but it was " + remoteValue), ("expected field(s) " + selector + " to not have value " + givenValue + ", ") + "but it was");
_addProperty('trueOnRemote', function() {
var expr, fn, remoteValue;
expr = this._obj;
fn = _exprAsFunction(expr);
remoteValue = casper.evaluate(fn);
return this.assert(remoteValue, "expected expression " + this._obj + " to be true, but it was " + remoteValue, "expected expression " + this._obj + " to not be true, but itw as " + remoteValue);
});
return _addProperty('visible', function() {
var selector;
selector = this._obj;
expect(selector).to.be.inDOM;
return this.assert(casper.visible(selector), 'expected selector #{this} to be visible, but it was not', 'expected selector #{this} to not be, but it was');
});
};

@@ -103,0 +198,0 @@

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

(function(){var t;t=function(t,e){var i,s,r,n,o;s=[];i=[];o=function(t,e){var i;if(typeof t==="string"){i=new RegExp("^"+t+"$")}else if(_.isRegExp(t)){i=t}else{throw new Error("Test received "+t+", but expected string",+" or regular expression.")}return i.test(e)};assert.casper={};n=function(e,i){return t.Assertion.addProperty(e,i)};r=function(e,i){return t.Assertion.addMethod(e,i)};n("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")});n("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")});n("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("matchTitle",function(){var t,e;t=this._obj;e=casper.getTitle();return this.assert(o(t,e),"expected title #{this} to match #{exp}, but it did not","expected title #{this} to not match #{exp}, but it did")});n("matchCurrentUrl",function(){var t,e;e=this._obj;t=casper.getCurrentUrl();return this.assert(o(e,t),"expected url #{exp} to match #{this}, but it did not","expected url #{exp} to not match #{this}, but it did")});n("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")});r("textMatch",function(t){var e,i;e=this._obj;i=casper.fetchText(e);return this.assert(o(t,i),"expected '"+e+"' to match "+t+", but it did not","expected '"+e+"' to not match "+t+", but it did")});return r("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")})};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 i,s,n,r,o,u,c;n=[];s=[];i=t.assert;o=function(e,i){return t.Assertion.addProperty(e,i)};r=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){var i;if(typeof t==="string"){i=new RegExp("^"+t+"$")}else if(_.isRegExp(t)){i=t}else{return _.isEqual(t,e);throw new Error("Test received "+t+", but expected string",+" or regular expression.")}return i.test(e)};r("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")});r("matchOnRemote",function(t){var e,i,s;e=this._obj;i=u(e);s=casper.evaluate(i);return this.assert(c(t,s),"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")});r("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);

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

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

@@ -29,3 +29,5 @@ "license": "MIT",

},
"dependencies": {},
"dependencies": {
"lodash": ">= 0.8"
},
"devDependencies": {

@@ -35,10 +37,7 @@ "icolor": "*",

"glob": "*",
"lodash": "*",
"semver": "*",
"coffee-script": ">= 1.3.3",
"uglify-js2": "*",
"jshint": ">= 0.9.1",
"jquery": ">= 1.8.2",
"underscore.string": ">= 2.3"
}
}

Sorry, the diff of this file is not supported yet

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