Skip to content

Add a set of custom matchers for HTML and CSS related checks, using jQuery.

License

Notifications You must be signed in to change notification settings

sudhirbits/jasmine-jquery-matchers

 
 

Repository files navigation

Jasmine jQuery Matchers Version Build Status Dependency Status Coverage Status

Adds a set of custom matchers for HTML and CSS related checks, using jQuery.

The matchers provide custom error messages that try to be as helpful as possible, so that when things fail you can quickly pinpoint the problem.

Installation

If you are using npm to manage your dependencies:

$ npm install --save-dev jasmine-jquery-matchers

If you are using bower:

$ bower install --save-dev jasmine-jquery-matchers

Otherwise, simply download dist/jasmine-jquery-matchers.js and include it in your test runner file (or add it to your jasmine.yml file if you're using Ruby with jasmine-gem). Remember to also include jQuery, as jasmine-jquery-matchers relies on it.

Usage

Load these matchers in a beforeEach block, and then use them like any other matcher:

expect(this.$el).toHaveText('Hello world!');

AMD/CommonJS

If you are using AMD or CommonJS, require normally:

var matchers = require('jasmine-jquery-matchers');

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

Global

Otherwise, use window['jasmine-jquery-matchers']:

var matchers = window['jasmine-jquery-matchers'];

describe('My suite', function () {
  beforeEach(function () {
    jasmine.addMatchers(matchers);
  });

  it('passes if the element has the specified class', function () {
    expect($('<div class="some-class"></div>')).toHaveClass('some-class');
  });
});

List of matchers

  • toExist
  • toHaveLength
  • toHaveId
  • toHaveClass
  • toHaveTag
  • toHaveAttr
  • toHaveProp
  • toHaveText
  • toHaveData
  • toHaveValue
  • toHaveCss
  • toBeChecked
  • toBeDisabled
  • toBeEmpty
  • toBeHidden
  • toBeSelected
  • toBeVisible
  • toBeFocused
  • toBeInDom
  • toBeMatchedBy
  • toHaveDescendant
  • toHaveDescendantWithText

If you want to see usage examples, look at test/specs/matchers.js

Meta

Contributors

License

Copyright (c) 2015 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Add a set of custom matchers for HTML and CSS related checks, using jQuery.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%