npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

casper-chai

v0.3.0

Published

Extends Chai with assertions for CasperJS testing.

Downloads

962

Readme

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.open("http://www.google.com")

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

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

Examples

Say we have a page like this:

<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>

Here are some assertions that pass

expect(/Casper/).to.matchTitle
'Casper-Chai Example'.should.matchTitle
'site.css'.should.be.loaded
'body > header'.should.be.inDOM
'document.querySelectorAll('li').length'.should.evaluate.to.be.above(2)
'#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

'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 and check out the unit tests.

Installation

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');
chai.use(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.