High Level DOM Assertions for QUnit
Clone or download
Permalink
Failed to load latest commit information.
lib Cast elements to `HTMLInputElement` where necessary Sep 22, 2018
tests tests: Adjust `setResolver()` import Sep 10, 2018
vendor Add `qunit-dom` dummy module to allow imports Jul 17, 2018
.babelrc Use Babel to transpile ES6 class syntax Oct 8, 2017
.editorconfig Initial Commit from Ember CLI v2.15.0-beta.2 Aug 30, 2017
.ember-cli Ember: Set "outputPath" to "dist/ember" Aug 30, 2017
.eslintrc.js Initial Commit from Ember CLI v2.15.0-beta.2 Aug 30, 2017
.gitignore Replace `rollup-plugin-babel` with `rollup-plugin-typescript` Jul 2, 2018
.npmignore Update `.npmignore` file Jul 17, 2018
.travis.yml CI: Skip `dependabot` branches Aug 31, 2018
.watchmanconfig Initial Commit from Ember CLI v2.15.0-beta.2 Aug 30, 2017
API.md Bump documentation from 5.3.2 to 8.1.2 (#127) Sep 10, 2018
CHANGELOG.md Update Changelog Sep 6, 2018
LICENSE.md fix copyright notice Jan 3, 2018
README.md README: Update contribution instructions Aug 13, 2018
documentation.yml Bump documentation from 5.3.2 to 8.1.2 (#127) Sep 10, 2018
ember-cli-build.js Initial Commit from Ember CLI v2.15.0-beta.2 Aug 30, 2017
index.js Add `qunit-dom` dummy module to allow imports Jul 17, 2018
package.json Bump ember-cli-inject-live-reload from 1.8.2 to 2.0.1 (#170) Oct 23, 2018
rollup.config.js Replace `rollup-plugin-babel` with `rollup-plugin-typescript` Jul 2, 2018
testem.js testem: Use `--no-sandbox` on TravisCI Jan 30, 2018
tsconfig.json tsconfig: Add `ES6` lib Sep 22, 2018
yarn.lock Bump ember-cli-inject-live-reload from 1.8.2 to 2.0.1 (#170) Oct 23, 2018

README.md

qunit-dom

TravisCI Build Status Latest NPM release

High Level DOM Assertions for QUnit

assert.dom('h1').exists();
assert.dom('h1').hasClass('title');
assert.dom('h1').hasText('Welcome to Ember, John Doe!');

assert.dom('input').isFocused();
assert.dom('input').hasValue(/.+ Doe/);
assert.dom('input').hasAttribute('type', 'text');

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 welcoming', function(assert) {
  assert.dom('#title').hasText('Welcome to QUnit');
});

All available assertions are documented in API.md.

A basic codemod to automatically convert your assertions is available at https://github.com/simplabs/qunit-dom-codemod.

TypeScript

qunit-dom includes type definition files, but the way it extends QUnit means that you need import it somewhere so that TS and your editor can pick up the types. It is recommended to add the following line to your tests/test-helper.ts file:

import 'qunit-dom';

Rename your tests/test-helper.js to .ts if you do not have such a file yet.

Contributing

How to Run Tests

yarn test

How to Generate the Documentation

yarn docs

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.