Need help with qunit-dom?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

simplabs
149 Stars 106 Forks MIT License 1.3K Commits 12 Opened issues

Description

High Level DOM Assertions for QUnit

Services available

!
?

Need anything else?

Contributors list

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

Ember projects using
ember-qunit
v5.x and above

Import and run the

setup
function in your
test-helper.js
file:
// tests/test-helper.js
import * as QUnit from 'qunit';
import { setup } from 'qunit-dom';

//...

setup(QUnit.assert);

setApplication(Application.create(config.APP));

start();

//...

This will attach the APIs to QUnit's

assert
object.

Ember projects using
ember-qunit
v4.x and below

qunit-dom
will automatically attach the APIs to QUnit's
assert
object. No extra setup required :tada:.

 Tag

Load

qunit-dom.js
after
qunit.js
:

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

See CONTRIBUTING.md.

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.