Skip to content

Turbo87/qunit-dom

 
 

Repository files navigation

qunit-dom

TravisCI Build Status Latest NPM release

DOM element assertions for QUnit

Install

npm

npm install --save-dev qunit-dom

or using yarn:

yarn add --dev qunit-dom

(This is the recommended method for Ember projects.)

<script> Tag

Load qunit-dom.js after qunit.js:

<script src="https://unpkg.com/qunitjs/qunit/qunit.js"></script>
<script src="https://unpkg.com/qunit-dom/dist/qunit-dom.js"></script>

Usage

Once installed the DOM element assertions are available at assert.dom.*:

test('the title is friendly', function(assert) {
  assert.dom.textContains('#title', 'Welcome');
});

Assertions

exists(selector, [options], [message])

missing(selector, [message])

Assert an HTMLElement (or multiple) matching the selector exists.

assert.dom.exists('#title');
assert.dom.exists('.choice', { count: 4 });
assert.dom.missing('.should-not-exist');

focused(selector|element, [message])

notFocused(selector|element, [message])

Assert that the HTMLElement is or is not currently focused.

assert.dom.focused('input.email');
assert.dom.notFocused(document.querySelector('input[type="password"]'));

textContains(selector|element, text, [message])

Assert that the text of the HTMLElement contains the given text, using textContent.

assert.dom.textContains('#title', 'Welcome');
assert.dom.textContains(document.querySelector('#title'), 'Welcome');

textMatches(selector|element, regex, [message])

Assert that the text of the HTMLElement matches the given regular expression, using textContent.

assert.dom.textMatches('.foo', /[12]\d{3}/);
assert.dom.textMatches(document.querySelector('.foo'), /[12]\d{3}/);

Related

  • chai-dom – DOM assertions for the Chai assertion library using vanilla JavaScript
  • chai-jquery – jQuery assertions for chai

License

qunit-dom is developed by and © simplabs GmbH and contributors. It is released under the MIT License.

About

DOM element assertions for QUnit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 94.7%
  • HTML 5.3%