diff --git a/API.md b/API.md index 4b96b5f9f..96434ea7d 100644 --- a/API.md +++ b/API.md @@ -2,119 +2,119 @@ ### Table of Contents -* [assert.dom()][1] -* [DOMAssertions][2] - * [exists][3] - * [Parameters][4] - * [Examples][5] - * [doesNotExist][6] - * [Parameters][7] - * [Examples][8] - * [isChecked][9] - * [Parameters][10] - * [Examples][11] - * [isNotChecked][12] - * [Parameters][13] - * [Examples][14] - * [isFocused][15] - * [Parameters][16] - * [Examples][17] - * [isNotFocused][18] - * [Parameters][19] - * [Examples][20] - * [isRequired][21] - * [Parameters][22] - * [Examples][23] - * [isNotRequired][24] - * [Parameters][25] - * [Examples][26] - * [isValid][27] - * [Parameters][28] - * [Examples][29] - * [isNotValid][30] - * [Parameters][31] - * [Examples][32] - * [isVisible][33] - * [Parameters][34] - * [Examples][35] - * [isNotVisible][36] - * [Parameters][37] - * [Examples][38] - * [hasAttribute][39] - * [Parameters][40] - * [Examples][41] - * [doesNotHaveAttribute][42] - * [Parameters][43] - * [Examples][44] - * [hasAria][45] - * [Parameters][46] - * [Examples][47] - * [doesNotHaveAria][48] - * [Parameters][49] - * [Examples][50] - * [hasProperty][51] - * [Parameters][52] - * [Examples][53] - * [isDisabled][54] - * [Parameters][55] - * [Examples][56] - * [isNotDisabled][57] - * [Parameters][58] - * [Examples][59] - * [hasClass][60] - * [Parameters][61] - * [Examples][62] - * [doesNotHaveClass][63] - * [Parameters][64] - * [Examples][65] - * [hasStyle][66] - * [Parameters][67] - * [Examples][68] - * [hasPseudoElementStyle][69] - * [Parameters][70] - * [Examples][71] - * [doesNotHaveStyle][72] - * [Parameters][73] - * [Examples][74] - * [doesNotHavePseudoElementStyle][75] - * [Parameters][76] - * [Examples][77] - * [hasText][78] - * [Parameters][79] - * [Examples][80] - * [hasAnyText][81] - * [Parameters][82] - * [Examples][83] - * [hasNoText][84] - * [Parameters][85] - * [Examples][86] - * [includesText][87] - * [Parameters][88] - * [Examples][89] - * [doesNotIncludeText][90] - * [Parameters][91] - * [Examples][92] - * [hasValue][93] - * [Parameters][94] - * [Examples][95] - * [hasAnyValue][96] - * [Parameters][97] - * [Examples][98] - * [hasNoValue][99] - * [Parameters][100] - * [Examples][101] - * [matchesSelector][102] - * [Parameters][103] - * [Examples][104] - * [doesNotMatchSelector][105] - * [Parameters][106] - * [Examples][107] - * [hasTagName][108] - * [Parameters][109] - * [Examples][110] - * [doesNotHaveTagName][111] - * [Parameters][112] - * [Examples][113] +- [assert.dom()](#assertdom) +- [DOMAssertions](#domassertions) + - [exists](#exists) + - [Parameters](#parameters) + - [Examples](#examples) + - [doesNotExist](#doesnotexist) + - [Parameters](#parameters-1) + - [Examples](#examples-1) + - [isChecked](#ischecked) + - [Parameters](#parameters-2) + - [Examples](#examples-2) + - [isNotChecked](#isnotchecked) + - [Parameters](#parameters-3) + - [Examples](#examples-3) + - [isFocused](#isfocused) + - [Parameters](#parameters-4) + - [Examples](#examples-4) + - [isNotFocused](#isnotfocused) + - [Parameters](#parameters-5) + - [Examples](#examples-5) + - [isRequired](#isrequired) + - [Parameters](#parameters-6) + - [Examples](#examples-6) + - [isNotRequired](#isnotrequired) + - [Parameters](#parameters-7) + - [Examples](#examples-7) + - [isValid](#isvalid) + - [Parameters](#parameters-8) + - [Examples](#examples-8) + - [isNotValid](#isnotvalid) + - [Parameters](#parameters-9) + - [Examples](#examples-9) + - [isVisible](#isvisible) + - [Parameters](#parameters-10) + - [Examples](#examples-10) + - [isNotVisible](#isnotvisible) + - [Parameters](#parameters-11) + - [Examples](#examples-11) + - [hasAttribute](#hasattribute) + - [Parameters](#parameters-12) + - [Examples](#examples-12) + - [doesNotHaveAttribute](#doesnothaveattribute) + - [Parameters](#parameters-13) + - [Examples](#examples-13) + - [hasAria](#hasaria) + - [Parameters](#parameters-14) + - [Examples](#examples-14) + - [doesNotHaveAria](#doesnothavearia) + - [Parameters](#parameters-15) + - [Examples](#examples-15) + - [hasProperty](#hasproperty) + - [Parameters](#parameters-16) + - [Examples](#examples-16) + - [isDisabled](#isdisabled) + - [Parameters](#parameters-17) + - [Examples](#examples-17) + - [isNotDisabled](#isnotdisabled) + - [Parameters](#parameters-18) + - [Examples](#examples-18) + - [hasClass](#hasclass) + - [Parameters](#parameters-19) + - [Examples](#examples-19) + - [doesNotHaveClass](#doesnothaveclass) + - [Parameters](#parameters-20) + - [Examples](#examples-20) + - [hasStyle](#hasstyle) + - [Parameters](#parameters-21) + - [Examples](#examples-21) + - [hasPseudoElementStyle](#haspseudoelementstyle) + - [Parameters](#parameters-22) + - [Examples](#examples-22) + - [doesNotHaveStyle](#doesnothavestyle) + - [Parameters](#parameters-23) + - [Examples](#examples-23) + - [doesNotHavePseudoElementStyle](#doesnothavepseudoelementstyle) + - [Parameters](#parameters-24) + - [Examples](#examples-24) + - [hasText](#hastext) + - [Parameters](#parameters-25) + - [Examples](#examples-25) + - [hasAnyText](#hasanytext) + - [Parameters](#parameters-26) + - [Examples](#examples-26) + - [hasNoText](#hasnotext) + - [Parameters](#parameters-27) + - [Examples](#examples-27) + - [includesText](#includestext) + - [Parameters](#parameters-28) + - [Examples](#examples-28) + - [doesNotIncludeText](#doesnotincludetext) + - [Parameters](#parameters-29) + - [Examples](#examples-29) + - [hasValue](#hasvalue) + - [Parameters](#parameters-30) + - [Examples](#examples-30) + - [hasAnyValue](#hasanyvalue) + - [Parameters](#parameters-31) + - [Examples](#examples-31) + - [hasNoValue](#hasnovalue) + - [Parameters](#parameters-32) + - [Examples](#examples-32) + - [matchesSelector](#matchesselector) + - [Parameters](#parameters-33) + - [Examples](#examples-33) + - [doesNotMatchSelector](#doesnotmatchselector) + - [Parameters](#parameters-34) + - [Examples](#examples-34) + - [hasTagName](#hastagname) + - [Parameters](#parameters-35) + - [Examples](#examples-35) + - [doesNotHaveTagName](#doesnothavetagname) + - [Parameters](#parameters-36) + - [Examples](#examples-36) ## assert.dom() @@ -123,7 +123,7 @@ Once installed the DOM element assertions are available at `assert.dom(...).*`: **Parameters** * `target` **([string][114] | [HTMLElement][115])** A CSS selector that can be used to find elements using [`querySelector()`][116], or an \[HTMLElement]\[] (Not all assertions support both target types.) (optional, default `rootElement` or `document`) -* `rootElement` **[HTMLElement][115]?** The root element of the DOM in which to search for the `target` (optional, default `document`) +* `rootElement` **([HTMLElement][115] | [Document][152] | [ShadowRoot][153] | [null][154])?** The root element of the DOM in which to search for the `target` (optional, defaults `document` when `null` or not provided) **Examples** @@ -151,7 +151,7 @@ Assert an [HTMLElement][118] (or multiple) matching the `selector` exists. #### Examples ```javascript -assert.dom('#title').exists(); +assert.dom('#title').exists(); assert.dom('.choice').exists({ count: 4 }); ``` @@ -175,7 +175,7 @@ assert.dom('.should-not-exist').doesNotExist(); * **See**: [#isNotChecked][122] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is currently checked. Note: This also supports `aria-checked="true/false"`. @@ -194,7 +194,7 @@ assert.dom('input.active').isChecked(); * **See**: [#isChecked][123] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is currently unchecked. Note: This also supports `aria-checked="true/false"`. @@ -213,7 +213,7 @@ assert.dom('input.active').isNotChecked(); * **See**: [#isNotFocused][124] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is currently focused. #### Parameters @@ -230,7 +230,7 @@ assert.dom('input.email').isFocused(); * **See**: [#isFocused][125] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is not currently focused. #### Parameters @@ -247,7 +247,7 @@ assert.dom('input[type="password"]').isNotFocused(); * **See**: [#isNotRequired][126] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is currently required. #### Parameters @@ -264,7 +264,7 @@ assert.dom('input[type="text"]').isRequired(); * **See**: [#isRequired][127] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is currently not required. #### Parameters @@ -321,7 +321,7 @@ assert.dom('.input').isNotValid(); * **See**: [#isNotVisible][129] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` exists and is visible. Visibility is determined by asserting that: @@ -329,7 +329,7 @@ Visibility is determined by asserting that: * the element's offsetWidth and offsetHeight are non-zero * any of the element's DOMRect objects have a non-zero size -Additionally, visibility in this case means that the element is visible on the page, +Additionally, visibility in this case means that the element is visible on the page, but not necessarily in the viewport. #### Parameters @@ -342,7 +342,7 @@ but not necessarily in the viewport. #### Examples ```javascript -assert.dom('#title').isVisible(); +assert.dom('#title').isVisible(); assert.dom('.choice').isVisible({ count: 4 }); ``` @@ -350,7 +350,7 @@ assert.dom('.choice').isVisible({ count: 4 }); * **See**: [#isVisible][130] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` does not exist or is not visible on the page. Visibility is determined by asserting that: @@ -358,7 +358,7 @@ Visibility is determined by asserting that: * the element's offsetWidth or offsetHeight are zero * all of the element's DOMRect objects have a size of zero -Additionally, visibility in this case means that the element is visible on the page, +Additionally, visibility in this case means that the element is visible on the page, but not necessarily in the viewport. #### Parameters @@ -375,8 +375,8 @@ assert.dom('.foo').isNotVisible(); * **See**: [#doesNotHaveAttribute][131] -Assert that the [HTMLElement][118] has an attribute with the provided `name` -and optionally checks if the attribute `value` matches the provided text +Assert that the [HTMLElement][118] has an attribute with the provided `name` +and optionally checks if the attribute `value` matches the provided text or regular expression. #### Parameters @@ -414,8 +414,8 @@ assert.dom('input.username').doesNotHaveAttribute('disabled'); * **See**: [#doesNotHaveAria][134] -Assert that the [HTMLElement][118] has an ARIA attribute with the provided -`name` and optionally checks if the attribute `value` matches the provided +Assert that the [HTMLElement][118] has an ARIA attribute with the provided +`name` and optionally checks if the attribute `value` matches the provided text or regular expression. #### Parameters @@ -434,7 +434,7 @@ assert.dom('button').hasAria('pressed', 'true'); * **See**: [#hasAria][135] -Assert that the [HTMLElement][118] has no ARIA attribute with the +Assert that the [HTMLElement][118] has no ARIA attribute with the provided `name`. **Aliases:** `hasNoAria`, `lacksAria` @@ -454,8 +454,8 @@ assert.dom('button').doesNotHaveAria('pressed'); * **See**: [#doesNotHaveProperty][136] -Assert that the [HTMLElement][118] has a property with the provided `name` -and checks if the property `value` matches the provided text or regular +Assert that the [HTMLElement][118] has a property with the provided `name` +and checks if the property `value` matches the provided text or regular expression. #### Parameters @@ -474,7 +474,7 @@ assert.dom('input.password-input').hasProperty('type', 'password'); * **See**: [#isNotDisabled][137] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is disabled. #### Parameters @@ -491,7 +491,7 @@ assert.dom('.foo').isDisabled(); * **See**: [#isDisabled][138] -Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the +Assert that the [HTMLElement][118] or an [HTMLElement][118] matching the `selector` is not disabled. **Aliases:** `isEnabled` @@ -510,10 +510,10 @@ assert.dom('.foo').isNotDisabled(); * **See**: [#doesNotHaveClass][139] -Assert that the [HTMLElement][118] has the `expected` CSS class using +Assert that the [HTMLElement][118] has the `expected` CSS class using [`classList`][140]. -`expected` can also be a regular expression, and the assertion will return +`expected` can also be a regular expression, and the assertion will return true if any of the element's CSS classes match. #### Parameters @@ -535,10 +535,10 @@ assert.dom('input[type="password"]').hasClass(/.*password-input/); * **See**: [#hasClass][141] -Assert that the [HTMLElement][118] does not have the `expected` CSS class using +Assert that the [HTMLElement][118] does not have the `expected` CSS class using [`classList`][140]. -`expected` can also be a regular expression, and the assertion will return +`expected` can also be a regular expression, and the assertion will return true if none of the element's CSS classes match. **Aliases:** `hasNoClass`, `lacksClass` @@ -562,7 +562,7 @@ assert.dom('input[type="password"]').doesNotHaveClass(/username-.*-input/); * **See**: [#hasClass][141] -Assert that the \[HTMLElement]\[] has the `expected` style declarations using +Assert that the \[HTMLElement]\[] has the `expected` style declarations using [`window.getComputedStyle`][142]. #### Parameters @@ -573,9 +573,9 @@ Assert that the \[HTMLElement]\[] has the `expected` style declarations using #### Examples ```javascript -assert.dom('.progress-bar').hasStyle({ - opacity: 1, - display: 'block' +assert.dom('.progress-bar').hasStyle({ + opacity: 1, + display: 'block' }); ``` @@ -583,7 +583,7 @@ assert.dom('.progress-bar').hasStyle({ * **See**: [#hasClass][141] -Assert that the pseudo element for `selector` of the \[HTMLElement]\[] has the `expected` style declarations using +Assert that the pseudo element for `selector` of the \[HTMLElement]\[] has the `expected` style declarations using [`window.getComputedStyle`][142]. #### Parameters @@ -595,8 +595,8 @@ Assert that the pseudo element for `selector` of the \[HTMLElement]\[] has the ` #### Examples ```javascript -assert.dom('.progress-bar').hasPseudoElementStyle(':after', { - content: '";"', +assert.dom('.progress-bar').hasPseudoElementStyle(':after', { + content: '";"', }); ``` @@ -604,7 +604,7 @@ assert.dom('.progress-bar').hasPseudoElementStyle(':after', { * **See**: [#hasClass][141] -Assert that the \[HTMLElement]\[] does not have the `expected` style declarations using +Assert that the \[HTMLElement]\[] does not have the `expected` style declarations using [`window.getComputedStyle`][142]. #### Parameters @@ -615,9 +615,9 @@ Assert that the \[HTMLElement]\[] does not have the `expected` style declaration #### Examples ```javascript -assert.dom('.progress-bar').doesNotHaveStyle({ - opacity: 1, - display: 'block' +assert.dom('.progress-bar').doesNotHaveStyle({ + opacity: 1, + display: 'block' }); ``` @@ -625,7 +625,7 @@ assert.dom('.progress-bar').doesNotHaveStyle({ * **See**: [#hasClass][141] -Assert that the pseudo element for `selector` of the \[HTMLElement]\[] does not have the `expected` style declarations using +Assert that the pseudo element for `selector` of the \[HTMLElement]\[] does not have the `expected` style declarations using [`window.getComputedStyle`][142]. #### Parameters @@ -637,8 +637,8 @@ Assert that the pseudo element for `selector` of the \[HTMLElement]\[] does not #### Examples ```javascript -assert.dom('.progress-bar').doesNotHavePseudoElementStyle(':after', { - content: '";"', +assert.dom('.progress-bar').doesNotHavePseudoElementStyle(':after', { + content: '";"', }); ``` @@ -646,15 +646,15 @@ assert.dom('.progress-bar').doesNotHavePseudoElementStyle(':after', { * **See**: [#includesText][143] -Assert that the text of the [HTMLElement][118] or an [HTMLElement][118] -matching the `selector` matches the `expected` text, using the -[`textContent`][144] +Assert that the text of the [HTMLElement][118] or an [HTMLElement][118] +matching the `selector` matches the `expected` text, using the +[`textContent`][144] attribute and stripping/collapsing whitespace. `expected` can also be a regular expression. -> Note: This assertion will collapse whitespace if the type you pass in is a string. -> If you are testing specifically for whitespace integrity, pass your expected text +> Note: This assertion will collapse whitespace if the type you pass in is a string. +> If you are testing specifically for whitespace integrity, pass your expected text > in as a RegEx pattern. **Aliases:** `matchesText` @@ -667,10 +667,10 @@ attribute and stripping/collapsing whitespace. #### Examples ```javascript -//