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

    casper-chai

Extends Chai with assertions for CasperJS testing.


Version published
Weekly downloads
177
increased by40.48%
Maintainers
2
Install size
22.5 kB
Created
Weekly downloads
 

Readme

Source

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. Instead of using Casper's Tester you can use (in this case with Mocha and Chai):

describe("my page", function () {
  it("can be opened by Casper", function () {
    casper.open("http://www.google.com")

    casper.then(function () {
      expect(casper.currentHTTPStatus).to.equal(200);
    });

    casper.then(function () {
      expect("Google").to.matchTitle
    });
  });
});

Tests

NameDescription - passes when ...Example
attr(attr_name)exactly one element matching the selector has the given attributeexpect("#header_a").to.have.attr('target')
attrAny(attr_name)any element matching the selector has the given attributeexpect(".menu div").to.have.attr('data-bind')
attrAll(attr_name)all elements matching selector have the given attributeexpect('.menu div a').to.have.attr('href')
fieldValue(value)the named input provided has the given value"field_name".should.have.fieldValue("someValue")
inDOMwhen the given selector is in the DOMexpect('#header').to.be.inDOM
loadedwhen the given resource existsexpect('styles.css').to.be.loaded
matchCurrentUrlthe current URL matchesexpect(/https:\/\//).to.matchCurrentUrl
matchOnRemotecompare the remote evaluation to the given expressionexpect("typeof jQuery").to.matchOnRemote('undefined')
matchTitlethe current Title matchesexpect(/Google/).to.matchTitle
tagName(valid_tags)all elements matching the selectors are one of the given tagsexpect('.menu *').to.have.tagName(['div', 'span'])
textInDOMthe text can be found in the DOMexpect('About google').to.be.textInDOM
textMatch(expression) the text of the given selector matches the expression (a string or regular expression). expect('#my_header').to.have.textMatch("My Header")
trueOnRemotethe remote expression evaluates to something truthyexpect("true").to.be.trueOnRemote
visiblethe selector matches a visible elementexpect('#my_header').to.be.visible

More documentation and examples.

For even more examples, if you are cool with CoffeeScript, check out the unit tests.

Installation

Casper-Chai can be installed with npm using npm install casper-chai, or including build/casper-chai.js in a directory require will find it.

Add extensions to Chai with:

casper_chai = require('casper-chai');
chai.use(casper_chai);

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.

Keywords

FAQs

Last updated on 21 Oct 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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