パッケージの詳細

qunit-dom

mainmatter543.2kMIT3.4.0

High Level DOM Assertions for QUnit

browser, dom, html, qunit

readme

qunit-dom

CI 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');

[!NOTE] qunit-dom was written and is maintained by Mainmatter and contributors. We offer consulting, training, and team augmentation for web development teams – check out our website to learn more!

Install

npm

npm install --save-dev qunit-dom

or using yarn:

yarn add --dev qunit-dom

Ember projects using ember-qunit v6.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 < v6.x of ember-qunit

Install qunit-dom v2.0.0

<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

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 © Mainmatter GmbH and contributors. It is released under the MIT License.

更新履歴

Changelog

Release (2024-12-01)

qunit-dom 3.4.0 (minor)

:rocket: Enhancement

  • qunit-dom
    • #2153 feature: add includesValue/doesNotIncludeValue (@CvX)

Committers: 1

  • Jarek Radosz (@CvX)

Release (2024-11-10)

qunit-dom 3.3.0 (minor)

:rocket: Enhancement

  • qunit-dom
    • #2147 feature: add HTML matching methods (@CvX)

Committers: 1

  • Jarek Radosz (@CvX)

Release (2024-09-23)

qunit-dom 3.2.1 (patch)

:memo: Documentation

:house: Internal

Committers: 2

v3.2.0 (2024-06-27)

:rocket: Enhancement

  • qunit-dom, test-types-resolution-node, test-types-resolution-node16, test-types

:house: Internal

Committers: 1

v3.1.2 (2024-04-23)

:bug: Bug Fix

  • qunit-dom
    • #2105 fix(hasStyle): allow using camelCase properties inside assertion object (@BobrImperator)

Committers: 1

v3.1.1 (2024-04-09)

:bug: Bug Fix

:house: Internal

Committers: 2

v3.1.0 (2024-04-08)

:rocket: Enhancement

  • qunit-dom
    • #1976 Use getProperty for hasStyle assertions so testing can be done against css variables (@jkeen)

Committers: 2

v3.0.0 (2023-10-12)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

:house: Internal

Committers: 6

v3.0.0-rc.1 (2023-10-06)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

:house: Internal

Committers: 7

v2.0.0 (2021-08-30)

:boom: Breaking Change

:memo: Documentation

  • #983 doc(release): remove extra 'to' (@mrloop)
  • #919 Clarified how to update tests/test-helper.js when migrating ember-qunit to v5.x (@ijlee2)
  • #893 Extract contributing instructions to separate file (@locks)

:house: Internal

Committers: 5

v1.6.0 (2020-11-10)

:rocket: Enhancement

:bug: Bug Fix

:house: Internal

Committers: 3

v1.5.0 (2020-09-16)

:rocket: Enhancement

  • #782 Fix typing for hasProperty assertion (@wuron)

Committers: 1

  • Alexander Chepurnoy (@wuron)

v1.4.0 (2020-08-02)

:rocket: Enhancement

:memo: Documentation

  • #778 Add "qunit-plugin" keyword to package.json (@Krinkle)

:house: Internal

Committers: 3

v1.3.0 (2020-07-30)

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

  • #757 The name annotation results in inconsistent formatting (@pablobm)

:house: Internal

  • #712 Use ~ constraint for typescript dependency (@Turbo87)
  • #680 CI: Fix auto-dist-tag in GitHub Actions config (@Turbo87)

Committers: 3

v1.2.0 (2020-04-10)

:rocket: Enhancement

Committers: 2

v1.1.0 (2020-03-04)

:rocket: Enhancement

  • #634 Throw an error if an invalid rootElement is passed to assert.dom() (@Turbo87)

:memo: Documentation

:house: Internal

  • #635 Remove obsolete ember-cli-htmlbars-inline-precompile dev dependency (@Turbo87)
  • #619 Add GitHub Actions config (@scalvert)

Committers: 3

v1.0.0 (2020-02-02)

:boom: Breaking Change

:rocket: Enhancement

:bug: Bug Fix

  • #246 Make findTargets support a this.target of type Element (@dwilhelmi)

:house: Internal

Committers: 5

v0.9.2 (2019-11-12)

:rocket: Enhancement

  • #535 isChecked: Add support for aria-checked="true/false" (@Turbo87)

:memo: Documentation

Committers: 2

v0.9.1 (2019-10-28)

:rocket: Enhancement

:house: Internal

Committers: 4

v0.9.0 (2019-06-14)

:boom: Breaking Change

:memo: Documentation

:house: Internal

Committers: 2

v0.8.5 (2019-04-26)

:rocket: Enhancement

:house: Internal

Committers: 2

v0.8.4 (2019-01-04)

:rocket: Enhancement

:memo: Documentation

  • #233 helpers/node-list: Add missing @private declaration (@Turbo87)

:house: Internal

Committers: 2

v0.8.3 (2018-12-10)

:rocket: Enhancement

  • #198 Warn user when includesText assertion should expect collapsable whitespace (@happycollision)

:bug: Bug Fix

  • #213 Replace Array.from() for IE11 compatibility (@Turbo87)

:house: Internal

  • #207 TravisCI: Remove deprecated sudo: false option (@Turbo87)

Committers: 2

v0.8.2 (2018-11-27)

:rocket: Enhancement

  • #204 Adds support for count option to isVisible assertion (@lukemelia)

Committers: 1

v0.8.1 (2018-11-23)

:rocket: Enhancement

:memo: Documentation

  • #202 docs: Use {@link} instead of broken empty markdown links (@Turbo87)

:house: Internal

Committers: 3

v0.8.0 (2018-09-06)

:boom: Breaking Change

:memo: Documentation

Committers: 2

v0.7.1 (2018-07-17)

:rocket: Enhancement

  • #102 Add qunit-dom dummy module to allow imports (@Turbo87)

:bug: Bug Fix

Committers: 1

v0.7.0 (2018-07-04)

:boom: Breaking Change

  • #93 Let isNotVisible() pass if the element does not exist (@scalvert)

:rocket: Enhancement

:house: Internal

Committers: 2

v0.6.3 (2018-05-22)

:rocket: Enhancement

:memo: Documentation

:house: Internal

  • #87 Merge isDisabled and isNotDisabled helpers. (@Turbo87)

Committers: 2

v0.6.2 (2018-04-11)

:bug: Bug Fix

Committers: 1

v0.6.1 (2018-04-09)

:bug: Bug Fix

Committers: 1

v0.6.0 (2018-04-03)

:rocket: Enhancement

:bug: Bug Fix

  • #59 Add helpful error for invalid attributes to hasText. (@spencer516)

:house: Internal

Committers: 9

v0.5.0 (2018-02-03)

:boom: Breaking Change

:house: Internal

Committers: 2

v0.4.0 (2017-12-04)

:rocket: Enhancement

Committers: 1

v0.3.4 (2017-11-13)

:rocket: Enhancement

  • #36 Add doesNotIncludeText() assertion. (@Zureka)

Committers: 1

v0.3.3 (2017-10-21)

:rocket: Enhancement

  • #33 Ember: Convert rootElement to non-caching property. (@Turbo87)
  • #32 Rename hasTextContaining() to includesText(). (@Oreoz)
  • #31 Add includesText() alias. (@Oreoz)

:memo: Documentation

Committers: 2

v0.3.2 (2017-10-10)

:rocket: Enhancement

  • #28 Adds hasAttribute() and doesNotHaveAttribute() assertions. (@Turbo87)
  • #27 Add lacksClass() and lacksValue() aliases. (@Turbo87)
  • #26 Add doesNotHaveClass/hasNoClass() assertion. (@Turbo87)
  • #25 Add hasAnyValue() assertion and support for calling hasValue() without arguments. (@Turbo87)
  • #24 Add hasNoValue() assertion. (@Turbo87)

:house: Internal

  • #23 tests/has-value: Ensure empty value does not break the assertion. (@Turbo87)

Committers: 1

v0.3.1 (2017-10-09)

:rocket: Enhancement

:memo: Documentation

  • #16 Add @see directives to JSDoc comments. (@Turbo87)

Committers: 1

v0.3.0 (2017-10-09)

:boom: Breaking Change

  • #13 Replace contains/matchesText() with hasText() assertions. (@Turbo87)
  • #11 Rename missing(), focused() and notFocused() assertions. (@Turbo87)
  • #7 Use assert.dom(selector).exists() instead of assert.dom.exists(selector). (@Turbo87)

:bug: Bug Fix

  • #9 Fix default "rootElement" for Ember projects. (@Turbo87)

:memo: Documentation

:house: Internal

  • #14 Remove obsolete "rollup-plugin-commonjs" dependency. (@Turbo87)
  • #12 Refactoring of the internals. (@Turbo87)
  • #10 Test assert.dom() API instead of importing directly. (@Turbo87)
  • #5 Fix package.json metadata. (@Turbo87)
  • #2 make travis notify our slack room instead of emailing. (@marcoow)

Committers: 2