Skip to content

Latest commit

 

History

History
435 lines (267 loc) · 12.5 KB

API.md

File metadata and controls

435 lines (267 loc) · 12.5 KB

API

assert.dom()

Once installed the DOM element assertions are available at assert.dom(...).*:

Parameters

  • target (string | HTMLElement) A CSS selector that can be used to find elements using querySelector(), or an HTMLElement (Not all assertions support both target types.) (optional, default rootElement or document)
  • rootElement HTMLElement? The root element of the DOM in which to search for the target (optional, default document)

Examples

test('the title exists', function(assert) {
  assert.dom('#title').exists();
});

Assertions

exists

Assert an HTMLElement (or multiple) matching the selector exists.

Parameters

Examples

assert.dom('#title').exists();
assert.dom('.choice').exists({ count: 4 });

doesNotExist

Assert an HTMLElement matching the selector does not exists.

Parameters

Examples

assert.dom('.should-not-exist').doesNotExist();

isChecked

Assert that the HTMLElement or an HTMLElement matching the selector is currently checked.

Parameters

Examples

assert.dom('input.active').isChecked();

isNotChecked

Assert that the HTMLElement or an HTMLElement matching the selector is currently unchecked.

Parameters

Examples

assert.dom('input.active').isNotChecked();

isFocused

Assert that the HTMLElement or an HTMLElement matching the selector is currently focused.

Parameters

Examples

assert.dom('input.email').isFocused();

isNotFocused

Assert that the HTMLElement or an HTMLElement matching the selector is not currently focused.

Parameters

Examples

assert.dom('input[type="password"]').isNotFocused();

isRequired

Assert that the HTMLElement or an HTMLElement matching the selector is currently required.

Parameters

Examples

assert.dom('input[type="text"]').isRequired();

isNotRequired

Assert that the HTMLElement or an HTMLElement matching the selector is currently not required.

Parameters

Examples

assert.dom('input[type="text"]').isNotRequired();

isVisible

Assert that the HTMLElement or an HTMLElement matching the selector is visible. Visibility is determined with the hueristic used in jQuery's :visible pseudo-selector, specifically:

  • is the element's offsetWidth non-zero
  • is the element's offsetHeight non-zero
  • is the length of an element's DOMRect objects found via getClientRects() non-zero

Additionally, visibility in this case means that the element is visible on the page, but not necessarily in the viewport.

Parameters

Examples

assert.dom('.foo').isVisible();

isNotVisible

Assert that the HTMLElement or an HTMLElement matching the selector is not visible. Visibility is determined with the hueristic used in jQuery's :visible pseudo-selector, specifically:

  • is the element's offsetWidth non-zero
  • is the element's offsetHeight non-zero
  • is the length of an element's DOMRect objects found via getClientRects() non-zero

Additionally, visibility in this case means that the element is visible on the page, but not necessarily in the viewport.

Parameters

Examples

assert.dom('.foo').isNotVisible();

hasAttribute

Assert that the HTMLElement has an attribute with the provided name and optionally checks if the attribute value matches the provided text or regular expression.

Parameters

Examples

assert.dom('input.password-input').hasAttribute('type', 'password');

doesNotHaveAttribute

Assert that the HTMLElement has no attribute with the provided name.

Aliases: hasNoAttribute, lacksAttribute

Parameters

Examples

assert.dom('input.username').hasNoAttribute('disabled');

hasClass

Assert that the HTMLElement has the expected CSS class using classList.

Parameters

Examples

assert.dom('input[type="password"]').hasClass('secret-password-input');

doesNotHaveClass

Assert that the HTMLElement does not have the expected CSS class using classList.

Aliases: hasNoClass, lacksClass

Parameters

Examples

assert.dom('input[type="password"]').doesNotHaveClass('username-input');

hasText

Assert that the text of the HTMLElement or an HTMLElement matching the selector matches the expected text, using the textContent attribute and stripping/collapsing whitespace.

expected can also be a regular expression.

Parameters

Examples

// <h2 id="title">
//   Welcome to <b>QUnit</b>
// </h2>

assert.dom('#title').hasText('Welcome to QUnit');
assert.dom('.foo').hasText(/[12]\d{3}/);

hasAnyText

Assert that the textContent property of an HTMLElement is not empty.

Parameters

Examples

assert.dom('button.share').hasAnyText();

includesText

Assert that the text of the HTMLElement or an HTMLElement matching the selector contains the given text, using the textContent attribute.

Aliases: containsText, hasTextContaining

Parameters

Examples

assert.dom('#title').includesText('Welcome');

doesNotIncludeText

Assert that the text of the HTMLElement or an HTMLElement matching the selector does not include the given text, using the textContent attribute.

Aliases: doesNotContainText, doesNotHaveTextContaining

Parameters

Examples

assert.dom('#title').doesNotIncludeText('Welcome');

hasValue

Assert that the value property of an HTMLInputElement matches the expected text or regular expression.

If no expected value is provided, the assertion will fail if the value is an empty string.

Parameters

Examples

assert.dom('input.username').hasValue('HSimpson');

hasAnyValue

Assert that the value property of an HTMLInputElement is not empty.

Parameters

Examples

assert.dom('input.username').hasAnyValue();

hasNoValue

Assert that the value property of an HTMLInputElement is empty.

Aliases: lacksValue

Parameters

Examples

assert.dom('input.username').hasNoValue();