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.
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.
Load these matchers in a beforeEach
block, and then use them like any other matcher:
expect(this.$el).toHaveText('Hello world!');
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');
});
});
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');
});
});
- 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
- Code:
git clone git://github.com/unindented/jasmine-jquery-matchers.git
- Home: https://github.com/unindented/jasmine-jquery-matchers/
- Daniel Perez Alvarez ([email protected])
Copyright (c) 2015 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.