Socket
Socket
Sign inDemoInstall

casper-chai

Package Overview
Dependencies
0
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.8 to 0.2.0

31

docs/casper-chai.md
<!--- AUTO-GENERATED BY CAKEFILE. Do not edit! -->
Chai assertions for CasperJS
============================
Copyright (C) 2012 Brian M Hunt
Repository: http://github.com/brianmhunt/casper-chai.git
License: MIT (see LICENSE.txt)
Chai Tests
Casper-Chai Assertions
----------
The following are the tests that are added onto Chai Assertion.
The following are the assertion tests that are added onto Chai Assertion.
#### attr(attribute_name)

@@ -117,5 +106,5 @@

```javascript
".menuItem".has.tagName('li')
".menuItem".should.have.tagName('li')
"menu li *".has.tagName(['a', 'span'])
"menu li *".should.have.tagName(['a', 'span'])
```

@@ -129,9 +118,13 @@ #### textInDOM

```
#### textMatch
#### text
The text of the given selector matches the expression (a string
or regular expression).
The text of the given selector matches the expression if it is a regular expression,
or is equal to the text, if a string.
It supports the `contains` and `include` language chain to do partial matching
```javascript
expect("#element").to.have.textMatch(/case InSenSitIvE/i);
expect("#element").to.have.text(/case InSenSitIvE/i);
expect("#element").to.have.text("Welcome to My Site");
expect("#element").to.contain.text("Welcome");
```

@@ -138,0 +131,0 @@ #### trueOnRemote

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

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

@@ -26,16 +26,12 @@ "license": "MIT",

"scripts": {
"test": "cake test",
"test": "./node_modules/mocha-casperjs/bin/mocha-casperjs --casper-chai-path=lib/casper-chai --expect",
"lint": "jshint ./lib"
},
"devDependencies": {
"lodash": ">= 0.8",
"icolor": "*",
"chai": ">= 1.3.0",
"chai": ">= 1.8.1",
"mocha-casperjs": "0.1.x",
"mocha": ">= 1.13.0",
"glob": "*",
"semver": "*",
"coffee-script": ">= 1.3.3",
"uglify-js2": "*",
"underscore.string": ">= 2.3"
"semver": "*"
}
}

@@ -6,4 +6,4 @@ # 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)

It is an alternative to Casper's built-in [Tester][]. Instead of using
Casper's Tester you can use (in this case with [Mocha][] and Chai):
It is an alternative to Casper's built-in [Tester][] assertions. Instead of using
Casper's Tester you can use (in this case with [mocha-casperjs][] and Chai):

@@ -24,89 +24,59 @@ describe("my page", function () {

### Tests
### Examples
<table>
<thead>
<th>Name</th>
<th>Description - passes when ...</th>
<th>Example</th>
</thead>
<tbody>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attr'>attr(attr_name)</a></td>
<td>exactly one element matching the selector has the given attribute</td>
<td>expect("#header_a").to.have.attr('target')</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attrany'>attrAny(attr_name)</a></td>
<td>any element matching the selector has the given attribute</td>
<td>expect(".menu div").to.have.attr('data-bind')</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#attrall'>attrAll(attr_name)</a></td>
<td>all elements matching selector have the given attribute</td>
<td>expect('.menu div a').to.have.attr('href')</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#fieldvalue'>fieldValue(value)</a></td>
<td>the named input provided has the given value</td>
<td>"field_name".should.have.fieldValue("someValue")</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#indom'>inDOM</a></td>
<td>when the given selector is in the DOM</td>
<td>expect('#header').to.be.inDOM</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#loaded'>loaded</a></td>
<td>when the given resource exists</td>
<td>expect('styles.css').to.be.loaded</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#matchcurrenturl'>matchCurrentUrl</a></td>
<td>the current URL matches</td>
<td>expect(/https:\/\//).to.matchCurrentUrl
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#matchonremote'>matchOnRemote</a></td>
<td>compare the remote evaluation to the given expression</td>
<td>expect("typeof jQuery").to.matchOnRemote('undefined')</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#matchtitle'>matchTitle</a></td>
<td>the current Title matches</td>
<td>expect(/Google/).to.matchTitle</td>
</tr>
<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>
<td>expect('.menu *').to.have.tagName(['div', 'span'])</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#textindom'>textInDOM</a></td>
<td>the text can be found in the DOM</td>
<td>expect('About google').to.be.textInDOM</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#textmatch'>textMatch(expression)</a></td>
<td>
the text of the given selector matches the expression (a string or regular expression).
</td>
<td>expect('#my_header').to.have.textMatch("My Header")</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#trueonremote'>trueOnRemote</a></td>
<td>the remote expression evaluates to something truthy</td>
<td>expect("true").to.be.trueOnRemote</td>
</tr>
<tr>
<td><a href='casper-chai/blob/master/build/casper-chai.md#visible'>visible</a></td>
<td>the selector matches a visible element</td>
<td>expect('#my_header').to.be.visible</td>
</tr>
</tbody>
</table>
Say we have a page like this:
More [documentation and examples](https://github.com/brianmhunt/casper-chai/blob/master/build/casper-chai.md).
````html
<html>
<head>
<title>Casper-Chai Example</title>
<link rel="stylesheet" href="site.css" type="text/css">
</head>
<body>
<header>
<a href="javascript:void(0)" class="signin">Sign In</a>
</header>
<article>
<ul class="breadcrumbs">
<li>Home</li>
<li>Blog</li>
<li aria-selected="true">Using Chai in your casper tests</li>
</ul>
<div class="greeting">Hello</div>
<span class="greeting help">Need help?</span>
</article>
<footer>
<a href="/help" id="help-link" class="help">Help</a>
</footer>
</body>
</html>
````
For even more examples, if you are cool with
Here are some assertions that pass
````javascript
expect(/Casper/).to.matchTitle
'Casper-Chai Example'.should.matchTitle
'site.css'.should.be.loaded
'body > header'.should.be.inDOM
(function() { document.querySelectorAll('li').count === 3 }).should.be.trueOnRemote
'#help-link'.should.have.attribute('href')[0].and.equal("/help")
'ul.breadcrumbs li'.should.contain.an.element.with.attr('aria-selected')
'.greeting'.should.have.tagName(['div', 'span'])
'li[aria-selected]'.should.contain.text('Using Chai')
'header a'.should.have.text(/Sign/)
'.greeting'.should.not.have.text(/Bye/)
````
Here are some assertions that fail
````javascript
'li'.should.have.attr('aria-selected')
'li'.should.not.have.an.element.with.attr('aria-selected')
'.greeting'.should.not.have.tagName('span')
'.help'.should.have.text('Help')
'li[aria-selected]'.should.have.text('Using Chai')
````
See the [full documentation and more examples](https://github.com/brianmhunt/casper-chai/blob/master/docs/casper-chai.md), and if you are cool with
[CoffeeScript](http://coffeescript.org/), check out the [unit

@@ -120,3 +90,3 @@ tests](https://github.com/brianmhunt/casper-chai/blob/master/test/common.coffee).

including
[`build/casper-chai.js`](https://raw.github.com/brianmhunt/casper-chai/master/build/casper-chai.js)
[`casper-chai.coffee`](https://raw.github.com/brianmhunt/casper-chai/master/lib/casper-chai.coffee)
in a directory `require` will find it.

@@ -129,6 +99,4 @@

To build locally, clone the project and run `cake toast test` in the
project directory. You may have to run `npm install` to get dependencies
(which, obviously, requires [npm][] to be installed), and make sure `cake` is
available - which should be possible by running `npm install -g coffee-script`.
To develop and test casper-chai locally, clone the project and run `npm install` to get dependencies
(which, obviously, requires [npm][] to be installed). You will need `cake` to generate documentation - which should be possible by running `npm install -g coffee-script`. Also make sure you have the latest version of [casperjs][] installed.

@@ -138,4 +106,5 @@ [CasperJS]: http://casperjs.org/

[Mocha]: http://visionmedia.github.com/mocha/
[mocha-casperjs]: http://github.com/nathanboktae/mocha-casperjs
[npm]: https://npmjs.org/
[Tester]: http://casperjs.org/api.html#tester

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