Extends Chai with assertions for CasperJS testing.

Downloads in past


0.3.08 years ago11 years agoMinified + gzip package size for casper-chai in KB


Casper.JS Assertions for Chai Build Status
Casper–Chai provides a set of custom assertions for use with CasperJS. You get all the benefits of Chai to test with CasperJS.
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):
describe("my page", function () {
  it("can be opened by Casper", function () {"")

    casper.then(function () {

    casper.then(function () {


Say we have a page like this:
<title>Casper-Chai Example</title>
<link rel="stylesheet" href="site.css" type="text/css">
  <a href="javascript:void(0)" class="signin">Sign In</a>
  <ul class="breadcrumbs">
    <li aria-selected="true">Using Chai in your casper tests</li>
  <div class="greeting">Hello</div>
  <span class="greeting help">Need help?</span>
  <a href="/help" id="help-link" class="help">Help</a>
Here are some assertions that pass
````javascript expect(/Casper/).to.matchTitle 'Casper-Chai Example'.should.matchTitle 'site.css' 'body > header' 'document.querySelectorAll('li').length' '#help-link'.should.have.attribute('href')0.and.equal("/help") 'ul.breadcrumbs li''aria-selected') '.greeting'.should.have.tagName('div', 'span') 'liaria-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''aria-selected') '.greeting'.should.not.have.tagName('span') '.help'.should.have.text('Help') 'liaria-selected'.should.have.text('Using Chai') ````
See the full documentation and more examples and check out the unit tests.


Casper-Chai can be installed with npm using npm install casper-chai, or including casper-chai.js in a directory require will find it.
Add extensions to Chai with:
casper_chai = require('casper-chai');
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.