DOM element assertions for QUnit
npm install --save-dev qunit-dom
or using yarn
:
yarn add --dev qunit-dom
(This is the recommended method for Ember projects.)
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>
Once installed the DOM element assertions are available at assert.dom.*
:
test('the title is friendly', function(assert) {
assert.dom.textContains('#title', 'Welcome');
});
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');
Assert that the HTMLElement is or is not currently focused.
assert.dom.focused('input.email');
assert.dom.notFocused(document.querySelector('input[type="password"]'));
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');
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}/);
- chai-dom – DOM assertions for the Chai assertion library using vanilla JavaScript
- chai-jquery – jQuery assertions for chai
qunit-dom is developed by and © simplabs GmbH and contributors. It is released under the MIT License.