Chai-jQ

chai-jq is an alternate plugin for the Chai assertion library to provide jQuery-specific assertions.

Usage

Add chai-jq.js after your Chai script include.

<script src="chai.js"></script>
<script src="chai-jq.js"></script>

To see some of the plugin's assertions in action, see the test page for the project.

Plugin API

.$val(string|regexp)

Asserts that the element value matches a string or regular expression.

expect($("<input value='foo' />"))
  .to.have.$val("foo").and
  .to.have.$val(/^foo/);

See: http://api.jquery.com/val/

.$class(string)

Asserts that the element has a class match.

expect($("<div class='foo bar' />"))
  .to.have.$class("foo").and
  .to.have.$class("bar");

See: http://api.jquery.com/hasClass/

.$attr(name, string)

Asserts that the target has exactly the given named attribute, or asserts the target contains a subset of the attribute when using the include or contain modifiers.

expect($("<div id=\"hi\" foo=\"bar time\">/div>"))
  .to.have.$attr("id", "hi").and
  .to.contain.$attr("foo", "bar");

See: http://api.jquery.com/attr/

.$prop(name, value)

Asserts that the target has exactly the given named property.

expect($("<input type=\"checkbox\" checked=\"checked\" />"))
  .to.have.$prop("checked", true).and
  .to.have.$prop("type", "checkbox");

See: http://api.jquery.com/prop/

.$html(string)

Asserts that the target has exactly the given HTML, or asserts the target contains a subset of the HTML when using the include or contain modifiers.

expect($("<div><span>foo</span></div>"))
  .to.have.$html("<span>foo</span>").and
  .to.contain.$html("foo");

See: http://api.jquery.com/html/

.$text(string)

Asserts that the target has exactly the given text, or asserts the target contains a subset of the text when using the include or contain modifiers.

expect($("<div><span>foo</span> bar</div>"))
  .to.have.$text("foo bar").and
  .to.contain.$text("foo");

See: http://api.jquery.com/text/

Contributions

Please see the Contributions Guide for how to help out with the plugin.

We test all changes with Travis CI. Here's our current build status:

Build Status

Licenses

All code not otherwise specified is Copyright 2013 Ryan Roemer. Released under the MIT License.

This repository contains various libraries from other folks, and are licensed as follows:

History

0.0.1

Contributing

Community contributions are most welcome. Here are a couple of guidelines for contributions.

And, thanks!