Skip to content

dwilhelmi/qunit-dom

 
 

Repository files navigation

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.

About

High Level DOM Assertions for QUnit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 93.3%
  • JavaScript 5.3%
  • HTML 1.4%