@najemi-software/vitest-dom 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/esm/matchers/to-be-checked.d.ts +23 -0
- package/esm/matchers/to-be-checked.js +23 -0
- package/esm/matchers/to-be-checked.js.map +1 -1
- package/esm/matchers/to-be-disabled.d.ts +38 -0
- package/esm/matchers/to-be-disabled.js +38 -0
- package/esm/matchers/to-be-disabled.js.map +1 -1
- package/esm/matchers/to-be-empty-dom-element.d.ts +13 -0
- package/esm/matchers/to-be-empty-dom-element.js +13 -0
- package/esm/matchers/to-be-empty-dom-element.js.map +1 -1
- package/esm/matchers/to-be-empty.d.ts +15 -1
- package/esm/matchers/to-be-empty.js +15 -1
- package/esm/matchers/to-be-empty.js.map +1 -1
- package/esm/matchers/to-be-in-the-document.d.ts +11 -0
- package/esm/matchers/to-be-in-the-document.js +11 -0
- package/esm/matchers/to-be-in-the-document.js.map +1 -1
- package/esm/matchers/to-be-in-the-dom.d.ts +12 -1
- package/esm/matchers/to-be-in-the-dom.js +12 -1
- package/esm/matchers/to-be-in-the-dom.js.map +1 -1
- package/esm/matchers/to-be-invalid.d.ts +36 -0
- package/esm/matchers/to-be-invalid.js +36 -0
- package/esm/matchers/to-be-invalid.js.map +1 -1
- package/esm/matchers/to-be-partially-checked.d.ts +37 -0
- package/esm/matchers/to-be-partially-checked.js +37 -0
- package/esm/matchers/to-be-partially-checked.js.map +1 -1
- package/esm/matchers/to-be-required.d.ts +17 -0
- package/esm/matchers/to-be-required.js +17 -0
- package/esm/matchers/to-be-required.js.map +1 -1
- package/esm/matchers/to-be-visible.d.ts +26 -0
- package/esm/matchers/to-be-visible.js +26 -0
- package/esm/matchers/to-be-visible.js.map +1 -1
- package/esm/matchers/to-contain-element.d.ts +17 -0
- package/esm/matchers/to-contain-element.js +17 -0
- package/esm/matchers/to-contain-element.js.map +1 -1
- package/esm/matchers/to-contain-html.d.ts +10 -0
- package/esm/matchers/to-contain-html.js +10 -0
- package/esm/matchers/to-contain-html.js.map +1 -1
- package/esm/matchers/to-have-accessible-description.d.ts +25 -0
- package/esm/matchers/to-have-accessible-description.js +25 -0
- package/esm/matchers/to-have-accessible-description.js.map +1 -1
- package/esm/matchers/to-have-accessible-errormessage.d.ts +38 -0
- package/esm/matchers/to-have-accessible-errormessage.js +38 -0
- package/esm/matchers/to-have-accessible-errormessage.js.map +1 -1
- package/esm/matchers/to-have-accessible-name.d.ts +30 -0
- package/esm/matchers/to-have-accessible-name.js +30 -0
- package/esm/matchers/to-have-accessible-name.js.map +1 -1
- package/esm/matchers/to-have-attribute.d.ts +22 -0
- package/esm/matchers/to-have-attribute.js +22 -0
- package/esm/matchers/to-have-attribute.js.map +1 -1
- package/esm/matchers/to-have-class.d.ts +25 -0
- package/esm/matchers/to-have-class.js +25 -0
- package/esm/matchers/to-have-class.js.map +1 -1
- package/esm/matchers/to-have-description.d.ts +48 -1
- package/esm/matchers/to-have-description.js +48 -1
- package/esm/matchers/to-have-description.js.map +1 -1
- package/esm/matchers/to-have-display-value.d.ts +41 -0
- package/esm/matchers/to-have-display-value.js +41 -0
- package/esm/matchers/to-have-display-value.js.map +1 -1
- package/esm/matchers/to-have-errormessage.d.ts +40 -0
- package/esm/matchers/to-have-errormessage.js +40 -0
- package/esm/matchers/to-have-errormessage.js.map +1 -1
- package/esm/matchers/to-have-focus.d.ts +16 -0
- package/esm/matchers/to-have-focus.js +16 -0
- package/esm/matchers/to-have-focus.js.map +1 -1
- package/esm/matchers/to-have-form-values.d.ts +20 -0
- package/esm/matchers/to-have-form-values.js +20 -0
- package/esm/matchers/to-have-form-values.js.map +1 -1
- package/esm/matchers/to-have-style.d.ts +22 -0
- package/esm/matchers/to-have-style.js +22 -0
- package/esm/matchers/to-have-style.js.map +1 -1
- package/esm/matchers/to-have-text-content.d.ts +23 -0
- package/esm/matchers/to-have-text-content.js +23 -0
- package/esm/matchers/to-have-text-content.js.map +1 -1
- package/esm/matchers/to-have-value.d.ts +19 -0
- package/esm/matchers/to-have-value.js +19 -0
- package/esm/matchers/to-have-value.js.map +1 -1
- package/esm/matchers.d.ts +0 -624
- package/package.json +1 -1
|
@@ -1,2 +1,28 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* This allows you to check if an element is currently visible to the user.
|
|
5
|
+
*
|
|
6
|
+
* An element is visible if **all** the following conditions are met:
|
|
7
|
+
* * it does not have its css property display set to none
|
|
8
|
+
* * it does not have its css property visibility set to either hidden or collapse
|
|
9
|
+
* * it does not have its css property opacity set to 0
|
|
10
|
+
* * its parent element is also visible (and so on up to the top of the DOM tree)
|
|
11
|
+
* * it does not have the hidden attribute
|
|
12
|
+
* * if `<details />` it has the open attribute
|
|
13
|
+
* @example
|
|
14
|
+
* <div
|
|
15
|
+
* data-testid="zero-opacity"
|
|
16
|
+
* style="opacity: 0"
|
|
17
|
+
* >
|
|
18
|
+
* Zero Opacity
|
|
19
|
+
* </div>
|
|
20
|
+
*
|
|
21
|
+
* <div data-testid="visible">Visible Example</div>
|
|
22
|
+
*
|
|
23
|
+
* expect(getByTestId('zero-opacity')).not.toBeVisible()
|
|
24
|
+
* expect(getByTestId('visible')).toBeVisible()
|
|
25
|
+
* @see
|
|
26
|
+
* [testing-library/jest-dom#tobevisible](https://github.com/testing-library/jest-dom#tobevisible)
|
|
27
|
+
*/
|
|
2
28
|
export declare function toBeVisible(this: MatcherState, element: Element): MatcherResult;
|
|
@@ -22,6 +22,32 @@ function isElementVisible(element, previousElement) {
|
|
|
22
22
|
isAttributeVisible(element, previousElement) &&
|
|
23
23
|
(!element.parentElement || isElementVisible(element.parentElement, element)));
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* @description
|
|
27
|
+
* This allows you to check if an element is currently visible to the user.
|
|
28
|
+
*
|
|
29
|
+
* An element is visible if **all** the following conditions are met:
|
|
30
|
+
* * it does not have its css property display set to none
|
|
31
|
+
* * it does not have its css property visibility set to either hidden or collapse
|
|
32
|
+
* * it does not have its css property opacity set to 0
|
|
33
|
+
* * its parent element is also visible (and so on up to the top of the DOM tree)
|
|
34
|
+
* * it does not have the hidden attribute
|
|
35
|
+
* * if `<details />` it has the open attribute
|
|
36
|
+
* @example
|
|
37
|
+
* <div
|
|
38
|
+
* data-testid="zero-opacity"
|
|
39
|
+
* style="opacity: 0"
|
|
40
|
+
* >
|
|
41
|
+
* Zero Opacity
|
|
42
|
+
* </div>
|
|
43
|
+
*
|
|
44
|
+
* <div data-testid="visible">Visible Example</div>
|
|
45
|
+
*
|
|
46
|
+
* expect(getByTestId('zero-opacity')).not.toBeVisible()
|
|
47
|
+
* expect(getByTestId('visible')).toBeVisible()
|
|
48
|
+
* @see
|
|
49
|
+
* [testing-library/jest-dom#tobevisible](https://github.com/testing-library/jest-dom#tobevisible)
|
|
50
|
+
*/
|
|
25
51
|
export function toBeVisible(element) {
|
|
26
52
|
checkHtmlElement(element, toBeVisible, this);
|
|
27
53
|
const isInDocument = element.ownerDocument === element.getRootNode({ composed: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-be-visible.js","sourceRoot":"","sources":["../../src/matchers/to-be-visible.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,SAAS,cAAc,CAAC,OAAgB;IACpC,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,WAAY,CAAC;IAEhE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnE,OAAO,OAAO,KAAK,MAAM,IAAI,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,UAAU,IAAI,OAAO,KAAK,GAAG,CAAC;AACzG,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAgB,EAAE,eAAyB;IACn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K,CAAC,CAAC,EAAE;aAC5D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Allows you to assert whether an element contains another element as a descendant or not.
|
|
5
|
+
* @example
|
|
6
|
+
* <span data-testid="ancestor">
|
|
7
|
+
* <span data-testid="descendant"></span>
|
|
8
|
+
* </span>
|
|
9
|
+
*
|
|
10
|
+
* const ancestor = getByTestId('ancestor')
|
|
11
|
+
* const descendant = getByTestId('descendant')
|
|
12
|
+
* const nonExistantElement = getByTestId('does-not-exist')
|
|
13
|
+
* expect(ancestor).toContainElement(descendant)
|
|
14
|
+
* expect(descendant).not.toContainElement(ancestor)
|
|
15
|
+
* expect(ancestor).not.toContainElement(nonExistantElement)
|
|
16
|
+
* @see
|
|
17
|
+
* [testing-library/jest-dom#tocontainelement](https://github.com/testing-library/jest-dom#tocontainelement)
|
|
18
|
+
*/
|
|
2
19
|
export declare function toContainElement(this: MatcherState, container: Element, element: HTMLElement | SVGElement | null): MatcherResult;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { checkHtmlElement } from "./utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Allows you to assert whether an element contains another element as a descendant or not.
|
|
5
|
+
* @example
|
|
6
|
+
* <span data-testid="ancestor">
|
|
7
|
+
* <span data-testid="descendant"></span>
|
|
8
|
+
* </span>
|
|
9
|
+
*
|
|
10
|
+
* const ancestor = getByTestId('ancestor')
|
|
11
|
+
* const descendant = getByTestId('descendant')
|
|
12
|
+
* const nonExistantElement = getByTestId('does-not-exist')
|
|
13
|
+
* expect(ancestor).toContainElement(descendant)
|
|
14
|
+
* expect(descendant).not.toContainElement(ancestor)
|
|
15
|
+
* expect(ancestor).not.toContainElement(nonExistantElement)
|
|
16
|
+
* @see
|
|
17
|
+
* [testing-library/jest-dom#tocontainelement](https://github.com/testing-library/jest-dom#tocontainelement)
|
|
18
|
+
*/
|
|
2
19
|
export function toContainElement(container, element) {
|
|
3
20
|
checkHtmlElement(container, toContainElement, this);
|
|
4
21
|
if (element !== null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-contain-element.js","sourceRoot":"","sources":["../../src/matchers/to-contain-element.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,UAAU,gBAAgB,CAE5B,SAAkB,EAClB,OAAwC;IAExC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAEpD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACH,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;QACjC,OAAO,EAAE,GAAG,EAAE;YACV,OAAO;gBACH,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,CAAC;gBAC5F,EAAE;gBACF,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IACzE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;SAC7E,CAAC;aACG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
1
|
+
{"version":3,"file":"to-contain-element.js","sourceRoot":"","sources":["../../src/matchers/to-contain-element.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAE5B,SAAkB,EAClB,OAAwC;IAExC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IAEpD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACH,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;QACjC,OAAO,EAAE,GAAG,EAAE;YACV,OAAO;gBACH,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,CAAC;gBAC5F,EAAE;gBACF,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IACzE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,mBAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;SAC7E,CAAC;aACG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Assert whether a string representing a HTML element is contained in another element.
|
|
5
|
+
* @example
|
|
6
|
+
* <span data-testid="parent"><span data-testid="child"></span></span>
|
|
7
|
+
*
|
|
8
|
+
* expect(getByTestId('parent')).toContainHTML('<span data-testid="child"></span>')
|
|
9
|
+
* @see
|
|
10
|
+
* [testing-library/jest-dom#tocontainhtml](https://github.com/testing-library/jest-dom#tocontainhtml)
|
|
11
|
+
*/
|
|
2
12
|
export declare function toContainHTML(this: MatcherState, container: Element, htmlText: string): MatcherResult;
|
|
@@ -4,6 +4,16 @@ function getNormalizedHtml(container, htmlText) {
|
|
|
4
4
|
div.innerHTML = htmlText;
|
|
5
5
|
return div.innerHTML;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* @description
|
|
9
|
+
* Assert whether a string representing a HTML element is contained in another element.
|
|
10
|
+
* @example
|
|
11
|
+
* <span data-testid="parent"><span data-testid="child"></span></span>
|
|
12
|
+
*
|
|
13
|
+
* expect(getByTestId('parent')).toContainHTML('<span data-testid="child"></span>')
|
|
14
|
+
* @see
|
|
15
|
+
* [testing-library/jest-dom#tocontainhtml](https://github.com/testing-library/jest-dom#tocontainhtml)
|
|
16
|
+
*/
|
|
7
17
|
export function toContainHTML(container, htmlText) {
|
|
8
18
|
checkHtmlElement(container, toContainHTML, this);
|
|
9
19
|
if (typeof htmlText !== "string") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-contain-html.js","sourceRoot":"","sources":["../../src/matchers/to-contain-html.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,SAAS,iBAAiB,CAAC,SAAkB,EAAE,QAAgB;IAC3D,MAAM,GAAG,GAAG,SAAS,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACzD,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC;IACzB,OAAO,GAAG,CAAC,SAAS,CAAC;AACzB,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AkB,EAAE,QAAgB;IAClF,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;IAEjD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,gDAAgD,QAAQ,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,OAAO;QACH,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC1E,OAAO,EAAE,GAAG,EAAE;YACV,OAAO;gBACH,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,CAAC;gBAClF,WAAW;gBACX,KAAK,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;gBAC1C,WAAW;gBACX,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE;aAC7D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,3 +1,28 @@
|
|
|
1
1
|
import type { expect } from "vitest";
|
|
2
2
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* This allows to assert that an element has the expected [accessible description](https://w3c.github.io/accname/).
|
|
6
|
+
*
|
|
7
|
+
* You can pass the exact string of the expected accessible description, or you can make a
|
|
8
|
+
* partial match passing a regular expression, or by using either
|
|
9
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
10
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
11
|
+
* @example
|
|
12
|
+
* <a data-testid="link" href="/" aria-label="Home page" title="A link to start over">Start</a>
|
|
13
|
+
* <a data-testid="extra-link" href="/about" aria-label="About page">About</a>
|
|
14
|
+
* <img src="avatar.jpg" data-testid="avatar" alt="User profile pic" />
|
|
15
|
+
* <img src="logo.jpg" data-testid="logo" alt="Company logo" aria-describedby="t1" />
|
|
16
|
+
* <span id="t1" role="presentation">The logo of Our Company</span>
|
|
17
|
+
*
|
|
18
|
+
* expect(getByTestId('link')).toHaveAccessibleDescription()
|
|
19
|
+
* expect(getByTestId('link')).toHaveAccessibleDescription('A link to start over')
|
|
20
|
+
* expect(getByTestId('link')).not.toHaveAccessibleDescription('Home page')
|
|
21
|
+
* expect(getByTestId('extra-link')).not.toHaveAccessibleDescription()
|
|
22
|
+
* expect(getByTestId('avatar')).not.toHaveAccessibleDescription()
|
|
23
|
+
* expect(getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
|
|
24
|
+
* expect(getByTestId('logo')).toHaveAccessibleDescription('The logo of Our Company')
|
|
25
|
+
* @see
|
|
26
|
+
* [testing-library/jest-dom#tohaveaccessibledescription](https://github.com/testing-library/jest-dom#tohaveaccessibledescription)
|
|
27
|
+
*/
|
|
3
28
|
export declare function toHaveAccessibleDescription(this: MatcherState, htmlElement: Element, expectedAccessibleDescription?: string | RegExp | typeof expect.stringContaining): MatcherResult;
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { computeAccessibleDescription } from "dom-accessibility-api";
|
|
2
2
|
import { checkHtmlElement, getMessage } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* This allows to assert that an element has the expected [accessible description](https://w3c.github.io/accname/).
|
|
6
|
+
*
|
|
7
|
+
* You can pass the exact string of the expected accessible description, or you can make a
|
|
8
|
+
* partial match passing a regular expression, or by using either
|
|
9
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
10
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
11
|
+
* @example
|
|
12
|
+
* <a data-testid="link" href="/" aria-label="Home page" title="A link to start over">Start</a>
|
|
13
|
+
* <a data-testid="extra-link" href="/about" aria-label="About page">About</a>
|
|
14
|
+
* <img src="avatar.jpg" data-testid="avatar" alt="User profile pic" />
|
|
15
|
+
* <img src="logo.jpg" data-testid="logo" alt="Company logo" aria-describedby="t1" />
|
|
16
|
+
* <span id="t1" role="presentation">The logo of Our Company</span>
|
|
17
|
+
*
|
|
18
|
+
* expect(getByTestId('link')).toHaveAccessibleDescription()
|
|
19
|
+
* expect(getByTestId('link')).toHaveAccessibleDescription('A link to start over')
|
|
20
|
+
* expect(getByTestId('link')).not.toHaveAccessibleDescription('Home page')
|
|
21
|
+
* expect(getByTestId('extra-link')).not.toHaveAccessibleDescription()
|
|
22
|
+
* expect(getByTestId('avatar')).not.toHaveAccessibleDescription()
|
|
23
|
+
* expect(getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
|
|
24
|
+
* expect(getByTestId('logo')).toHaveAccessibleDescription('The logo of Our Company')
|
|
25
|
+
* @see
|
|
26
|
+
* [testing-library/jest-dom#tohaveaccessibledescription](https://github.com/testing-library/jest-dom#tohaveaccessibledescription)
|
|
27
|
+
*/
|
|
3
28
|
export function toHaveAccessibleDescription(htmlElement, expectedAccessibleDescription) {
|
|
4
29
|
checkHtmlElement(htmlElement, toHaveAccessibleDescription, this);
|
|
5
30
|
const actualAccessibleDescription = computeAccessibleDescription(htmlElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-have-accessible-description.js","sourceRoot":"","sources":["../../src/matchers/to-have-accessible-description.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,UAAU,2BAA2B,CAEvC,WAAoB,EACpB,6BAAgF;IAEhF,gBAAgB,CAAC,WAAW,EAAE,2BAA2B,EAAE,IAAI,CAAC,CAAC;IACjE,MAAM,2BAA2B,GAAG,4BAA4B,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,oBAAoB,GAAG,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAEpD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,oBAAoB,EAAE,CAAC;QACvB,yFAAyF;QACzF,8CAA8C;QAC9C,IAAI,GAAG,2BAA2B,KAAK,EAAE,CAAC;IAC9C,CAAC;SAAM,CAAC;QACJ,IAAI;YACA,6BAA6B,YAAY,MAAM;gBAC3C,CAAC,CAAC,6BAA6B,CAAC,IAAI,CAAC,2BAA2B,CAAC;gBACjE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,2BAA2B,EAAE,6BAA6B,CAAC,CAAC;IACtF,CAAC;IAED,OAAO;QACH,IAAI;QAEJ,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;YACxC,OAAO,UAAU,CACb,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAClB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,2BAA2B,CAAC,IAAI,EAAE,EACjE,SAAS,EACT,EAAE,CACL,EACD,oBAAoB,EAAE,8BAA8B,EACpD,6BAA6B,EAC7B,UAAU,EACV,2BAA2B,CAC9B,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
1
|
+
{"version":3,"file":"to-have-accessible-description.js","sourceRoot":"","sources":["../../src/matchers/to-have-accessible-description.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,2BAA2B,CAEvC,WAAoB,EACpB,6BAAgF;IAEhF,gBAAgB,CAAC,WAAW,EAAE,2BAA2B,EAAE,IAAI,CAAC,CAAC;IACjE,MAAM,2BAA2B,GAAG,4BAA4B,CAAC,WAAW,CAAC,CAAC;IAC9E,MAAM,oBAAoB,GAAG,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAEpD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,oBAAoB,EAAE,CAAC;QACvB,yFAAyF;QACzF,8CAA8C;QAC9C,IAAI,GAAG,2BAA2B,KAAK,EAAE,CAAC;IAC9C,CAAC;SAAM,CAAC;QACJ,IAAI;YACA,6BAA6B,YAAY,MAAM;gBAC3C,CAAC,CAAC,6BAA6B,CAAC,IAAI,CAAC,2BAA2B,CAAC;gBACjE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,2BAA2B,EAAE,6BAA6B,CAAC,CAAC;IACtF,CAAC;IAED,OAAO;QACH,IAAI;QAEJ,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;YACxC,OAAO,UAAU,CACb,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAClB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,2BAA2B,CAAC,IAAI,EAAE,EACjE,SAAS,EACT,EAAE,CACL,EACD,oBAAoB,EAAE,8BAA8B,EACpD,6BAA6B,EAC7B,UAAU,EACV,2BAA2B,CAC9B,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,2 +1,40 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* This allows you to assert that an element has the expected
|
|
5
|
+
* [accessible error message](https://w3c.github.io/aria/#aria-errormessage).
|
|
6
|
+
*
|
|
7
|
+
* You can pass the exact string of the expected accessible error message.
|
|
8
|
+
* Alternatively, you can perform a partial match by passing a regular expression
|
|
9
|
+
* or by using either
|
|
10
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
11
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <input aria-label="Has Error" aria-invalid="true" aria-errormessage="error-message" />
|
|
15
|
+
* <div id="error-message" role="alert">This field is invalid</div>
|
|
16
|
+
*
|
|
17
|
+
* <input aria-label="No Error Attributes" />
|
|
18
|
+
* <input aria-label="Not Invalid" aria-invalid="false" aria-errormessage="error-message" />
|
|
19
|
+
*
|
|
20
|
+
* // Inputs with Valid Error Messages
|
|
21
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage()
|
|
22
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage('This field is invalid')
|
|
23
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage(/invalid/i)
|
|
24
|
+
* expect(
|
|
25
|
+
* getByRole('textbox', {name: 'Has Error'}),
|
|
26
|
+
* ).not.toHaveAccessibleErrorMessage('This field is absolutely correct!')
|
|
27
|
+
*
|
|
28
|
+
* // Inputs without Valid Error Messages
|
|
29
|
+
* expect(
|
|
30
|
+
* getByRole('textbox', {name: 'No Error Attributes'}),
|
|
31
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
32
|
+
*
|
|
33
|
+
* expect(
|
|
34
|
+
* getByRole('textbox', {name: 'Not Invalid'}),
|
|
35
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
36
|
+
*
|
|
37
|
+
* @see
|
|
38
|
+
* [testing-library/jest-dom#tohaveaccessibleerrormessage](https://github.com/testing-library/jest-dom#tohaveaccessibleerrormessage)
|
|
39
|
+
*/
|
|
2
40
|
export declare function toHaveAccessibleErrorMessage<State extends MatcherState>(this: State, htmlElement: HTMLElement, expectedAccessibleErrorMessage?: string | RegExp | State): MatcherResult;
|
|
@@ -2,6 +2,44 @@ import { checkHtmlElement, getMessage, normalize } from "./utils.js";
|
|
|
2
2
|
const ariaInvalidName = "aria-invalid";
|
|
3
3
|
const validStates = ["false"];
|
|
4
4
|
// See `aria-errormessage` spec at https://www.w3.org/TR/wai-aria-1.2/#aria-errormessage
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* This allows you to assert that an element has the expected
|
|
8
|
+
* [accessible error message](https://w3c.github.io/aria/#aria-errormessage).
|
|
9
|
+
*
|
|
10
|
+
* You can pass the exact string of the expected accessible error message.
|
|
11
|
+
* Alternatively, you can perform a partial match by passing a regular expression
|
|
12
|
+
* or by using either
|
|
13
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
14
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* <input aria-label="Has Error" aria-invalid="true" aria-errormessage="error-message" />
|
|
18
|
+
* <div id="error-message" role="alert">This field is invalid</div>
|
|
19
|
+
*
|
|
20
|
+
* <input aria-label="No Error Attributes" />
|
|
21
|
+
* <input aria-label="Not Invalid" aria-invalid="false" aria-errormessage="error-message" />
|
|
22
|
+
*
|
|
23
|
+
* // Inputs with Valid Error Messages
|
|
24
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage()
|
|
25
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage('This field is invalid')
|
|
26
|
+
* expect(getByRole('textbox', {name: 'Has Error'})).toHaveAccessibleErrorMessage(/invalid/i)
|
|
27
|
+
* expect(
|
|
28
|
+
* getByRole('textbox', {name: 'Has Error'}),
|
|
29
|
+
* ).not.toHaveAccessibleErrorMessage('This field is absolutely correct!')
|
|
30
|
+
*
|
|
31
|
+
* // Inputs without Valid Error Messages
|
|
32
|
+
* expect(
|
|
33
|
+
* getByRole('textbox', {name: 'No Error Attributes'}),
|
|
34
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
35
|
+
*
|
|
36
|
+
* expect(
|
|
37
|
+
* getByRole('textbox', {name: 'Not Invalid'}),
|
|
38
|
+
* ).not.toHaveAccessibleErrorMessage()
|
|
39
|
+
*
|
|
40
|
+
* @see
|
|
41
|
+
* [testing-library/jest-dom#tohaveaccessibleerrormessage](https://github.com/testing-library/jest-dom#tohaveaccessibleerrormessage)
|
|
42
|
+
*/
|
|
5
43
|
export function toHaveAccessibleErrorMessage(htmlElement, expectedAccessibleErrorMessage) {
|
|
6
44
|
checkHtmlElement(htmlElement, toHaveAccessibleErrorMessage, this);
|
|
7
45
|
const to = this.isNot ? "not to" : "to";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-have-accessible-errormessage.js","sourceRoot":"","sources":["../../src/matchers/to-have-accessible-errormessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,CAAC;AAE9B,wFAAwF;AACxF,MAAM,UAAU,4BAA4B,CAExC,WAAwB,EACxB,8BAAwD;IAExD,gBAAgB,CAAC,WAAW,EAAE,4BAA4B,EAAE,IAAI,CAAC,CAAC;IAClE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,+BAA+B,CAAC;IAElG,mBAAmB;IACnB,MAAM,cAA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AAc,CAAC,EAAE,WAAW,IAAI,EAAE,CAAC;QAC/E,CAAC,CAAC,EAAE,CACX,CAAC;IAEF,OAAO;QACH,IAAI,EACA,8BAA8B,KAAK,SAAS;YACxC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;YAChB,CAAC,CAAC,8BAA8B,YAAY,MAAM;gBAChD,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC5C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,8BAA8B,CAAC;QAE9D,OAAO,EAAE,GAAG,EAAE;YACV,OAAO,UAAU,CACb,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,oBAAoB,EAAE,gCAAgC,EACtD,8BAA8B,IAAI,EAAE,EACpC,UAAU,EACV,KAAK,CACR,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
1
|
+
{"version":3,"file":"to-have-accessible-errormessage.js","sourceRoot":"","sources":["../../src/matchers/to-have-accessible-errormessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,eAAe,GAAG,cAAc,CAAC;AACvC,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,CAAC;AAE9B,wFAAwF;AACxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,4BAA4B,CAExC,WAAwB,EACxB,8BAAwD;IAExD,gBAAgB,CAAC,WAAW,EAAE,4BAA4B,EAAE,IAAI,CAAC,CAAC;IAClE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,+BAA+B,CAAC;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AAC,aAAa,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,WAAW,IAAI,EAAE,CAAC;QAC/E,CAAC,CAAC,EAAE,CACX,CAAC;IAEF,OAAO;QACH,IAAI,EACA,8BAA8B,KAAK,SAAS;YACxC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;YAChB,CAAC,CAAC,8BAA8B,YAAY,MAAM;gBAChD,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC5C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,8BAA8B,CAAC;QAE9D,OAAO,EAAE,GAAG,EAAE;YACV,OAAO,UAAU,CACb,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,EACzC,oBAAoB,EAAE,gCAAgC,EACtD,8BAA8B,IAAI,EAAE,EACpC,UAAU,EACV,KAAK,CACR,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,3 +1,33 @@
|
|
|
1
1
|
import type { expect } from "vitest";
|
|
2
2
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* This allows to assert that an element has the expected [accessible name](https://w3c.github.io/accname/).
|
|
6
|
+
* It is useful, for instance, to assert that form elements and buttons are properly labelled.
|
|
7
|
+
*
|
|
8
|
+
* You can pass the exact string of the expected accessible name, or you can make a
|
|
9
|
+
* partial match passing a regular expression, or by using either
|
|
10
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
11
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
12
|
+
* @example
|
|
13
|
+
* <img data-testid="img-alt" src="" alt="Test alt" />
|
|
14
|
+
* <img data-testid="img-empty-alt" src="" alt="" />
|
|
15
|
+
* <svg data-testid="svg-title"><title>Test title</title></svg>
|
|
16
|
+
* <button data-testid="button-img-alt"><img src="" alt="Test" /></button>
|
|
17
|
+
* <p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
|
|
18
|
+
* <button data-testid="svg-button"><svg><title>Test</title></svg></p>
|
|
19
|
+
* <div><svg data-testid="svg-without-title"></svg></div>
|
|
20
|
+
* <input data-testid="input-title" title="test" />
|
|
21
|
+
*
|
|
22
|
+
* expect(getByTestId('img-alt')).toHaveAccessibleName('Test alt')
|
|
23
|
+
* expect(getByTestId('img-empty-alt')).not.toHaveAccessibleName()
|
|
24
|
+
* expect(getByTestId('svg-title')).toHaveAccessibleName('Test title')
|
|
25
|
+
* expect(getByTestId('button-img-alt')).toHaveAccessibleName()
|
|
26
|
+
* expect(getByTestId('img-paragraph')).not.toHaveAccessibleName()
|
|
27
|
+
* expect(getByTestId('svg-button')).toHaveAccessibleName()
|
|
28
|
+
* expect(getByTestId('svg-without-title')).not.toHaveAccessibleName()
|
|
29
|
+
* expect(getByTestId('input-title')).toHaveAccessibleName()
|
|
30
|
+
* @see
|
|
31
|
+
* [testing-library/jest-dom#tohaveaccessiblename](https://github.com/testing-library/jest-dom#tohaveaccessiblename)
|
|
32
|
+
*/
|
|
3
33
|
export declare function toHaveAccessibleName(this: MatcherState, htmlElement: Element, expectedAccessibleName?: string | RegExp | typeof expect.stringContaining): MatcherResult;
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { computeAccessibleName } from "dom-accessibility-api";
|
|
2
2
|
import { checkHtmlElement, getMessage } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* This allows to assert that an element has the expected [accessible name](https://w3c.github.io/accname/).
|
|
6
|
+
* It is useful, for instance, to assert that form elements and buttons are properly labelled.
|
|
7
|
+
*
|
|
8
|
+
* You can pass the exact string of the expected accessible name, or you can make a
|
|
9
|
+
* partial match passing a regular expression, or by using either
|
|
10
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring)
|
|
11
|
+
* or [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
12
|
+
* @example
|
|
13
|
+
* <img data-testid="img-alt" src="" alt="Test alt" />
|
|
14
|
+
* <img data-testid="img-empty-alt" src="" alt="" />
|
|
15
|
+
* <svg data-testid="svg-title"><title>Test title</title></svg>
|
|
16
|
+
* <button data-testid="button-img-alt"><img src="" alt="Test" /></button>
|
|
17
|
+
* <p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
|
|
18
|
+
* <button data-testid="svg-button"><svg><title>Test</title></svg></p>
|
|
19
|
+
* <div><svg data-testid="svg-without-title"></svg></div>
|
|
20
|
+
* <input data-testid="input-title" title="test" />
|
|
21
|
+
*
|
|
22
|
+
* expect(getByTestId('img-alt')).toHaveAccessibleName('Test alt')
|
|
23
|
+
* expect(getByTestId('img-empty-alt')).not.toHaveAccessibleName()
|
|
24
|
+
* expect(getByTestId('svg-title')).toHaveAccessibleName('Test title')
|
|
25
|
+
* expect(getByTestId('button-img-alt')).toHaveAccessibleName()
|
|
26
|
+
* expect(getByTestId('img-paragraph')).not.toHaveAccessibleName()
|
|
27
|
+
* expect(getByTestId('svg-button')).toHaveAccessibleName()
|
|
28
|
+
* expect(getByTestId('svg-without-title')).not.toHaveAccessibleName()
|
|
29
|
+
* expect(getByTestId('input-title')).toHaveAccessibleName()
|
|
30
|
+
* @see
|
|
31
|
+
* [testing-library/jest-dom#tohaveaccessiblename](https://github.com/testing-library/jest-dom#tohaveaccessiblename)
|
|
32
|
+
*/
|
|
3
33
|
export function toHaveAccessibleName(htmlElement, expectedAccessibleName) {
|
|
4
34
|
checkHtmlElement(htmlElement, toHaveAccessibleName, this);
|
|
5
35
|
const actualAccessibleName = computeAccessibleName(htmlElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-have-accessible-name.js","sourceRoot":"","sources":["../../src/matchers/to-have-accessible-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,u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N,CAAC"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Allows you to check if a given element has an attribute or not.
|
|
5
|
+
*
|
|
6
|
+
* You can also optionally check that the attribute has a specific expected value or partial match using
|
|
7
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or
|
|
8
|
+
* [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
9
|
+
* @example
|
|
10
|
+
* <button
|
|
11
|
+
* data-testid="ok-button"
|
|
12
|
+
* type="submit"
|
|
13
|
+
* disabled
|
|
14
|
+
* >
|
|
15
|
+
* ok
|
|
16
|
+
* </button>
|
|
17
|
+
*
|
|
18
|
+
* expect(button).toHaveAttribute('disabled')
|
|
19
|
+
* expect(button).toHaveAttribute('type', 'submit')
|
|
20
|
+
* expect(button).not.toHaveAttribute('type', 'button')
|
|
21
|
+
* @see
|
|
22
|
+
* [testing-library/jest-dom#tohaveattribute](https://github.com/testing-library/jest-dom#tohaveattribute)
|
|
23
|
+
*/
|
|
2
24
|
export declare function toHaveAttribute(this: MatcherState, htmlElement: Element, name: string, expectedValue?: unknown): MatcherResult;
|
|
@@ -7,6 +7,28 @@ function getAttributeComment(stringify, name, value) {
|
|
|
7
7
|
? `element.hasAttribute(${stringify(name)})`
|
|
8
8
|
: `element.getAttribute(${stringify(name)}) === ${stringify(value)}`;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* Allows you to check if a given element has an attribute or not.
|
|
13
|
+
*
|
|
14
|
+
* You can also optionally check that the attribute has a specific expected value or partial match using
|
|
15
|
+
* [expect.stringContaining](https://jestjs.io/docs/en/expect.html#expectnotstringcontainingstring) or
|
|
16
|
+
* [expect.stringMatching](https://jestjs.io/docs/en/expect.html#expectstringmatchingstring-regexp).
|
|
17
|
+
* @example
|
|
18
|
+
* <button
|
|
19
|
+
* data-testid="ok-button"
|
|
20
|
+
* type="submit"
|
|
21
|
+
* disabled
|
|
22
|
+
* >
|
|
23
|
+
* ok
|
|
24
|
+
* </button>
|
|
25
|
+
*
|
|
26
|
+
* expect(button).toHaveAttribute('disabled')
|
|
27
|
+
* expect(button).toHaveAttribute('type', 'submit')
|
|
28
|
+
* expect(button).not.toHaveAttribute('type', 'button')
|
|
29
|
+
* @see
|
|
30
|
+
* [testing-library/jest-dom#tohaveattribute](https://github.com/testing-library/jest-dom#tohaveattribute)
|
|
31
|
+
*/
|
|
10
32
|
export function toHaveAttribute(htmlElement, name, expectedValue) {
|
|
11
33
|
checkHtmlElement(htmlElement, toHaveAttribute, this);
|
|
12
34
|
const isExpectedValuePresent = expectedValue !== undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-have-attribute.js","sourceRoot":"","sources":["../../src/matchers/to-have-attribute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,SAAS,cAAc,CAAC,SAAqC,EAAE,IAAY,EAAE,KAAc;IACvF,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAqC,EAAE,IAAY,EAAE,KAAc;IAC5F,OAAO,KAAK,KAAK,SAAS;QACtB,CAAC,CAAC,wBAAwB,SAAS,CAAC,IAAI,CAAC,GAAG;QAC5C,CAAC,CAAC,wBAAwB,SAAS,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,eAAe,CAE3B,WAAoB,EACpB,IAAY,EACZ,aAAuB;IAEvB,gBAAgB,CAAC,WAAW,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;I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AAC,IAAI,CAAC;YACxC,MAAM,iBAAiB,GAAG,YAAY;gBAClC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC;gBAC3D,CAAC,CAAC,IAAI,CAAC;YACX,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAClC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAC7C,SAAS,EACT,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,EAC9B;gBACI,cAAc,EAAE,sBAAsB;oBAClC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC;oBACzC,CAAC,CAAC,SAAS;gBACf,OAAO,EAAE,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC;aAC1E,CACJ,CAAC;YACF,OAAO,UAAU,CACb,IAAI,EACJ,OAAO,EACP,wBAAwB,EAAE,iBAAiB,EAC3C,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC,EACzD,UAAU,EACV,iBAAiB,CACpB,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -1,2 +1,27 @@
|
|
|
1
1
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Check whether the given element has certain classes within its `class` attribute.
|
|
5
|
+
*
|
|
6
|
+
* You must provide at least one class, unless you are asserting that an element does not have any classes.
|
|
7
|
+
* @example
|
|
8
|
+
* <button
|
|
9
|
+
* data-testid="delete-button"
|
|
10
|
+
* class="btn xs btn-danger"
|
|
11
|
+
* >
|
|
12
|
+
* delete item
|
|
13
|
+
* </button>
|
|
14
|
+
*
|
|
15
|
+
* <div data-testid="no-classes">no classes</div>
|
|
16
|
+
*
|
|
17
|
+
* const deleteButton = getByTestId('delete-button')
|
|
18
|
+
* const noClasses = getByTestId('no-classes')
|
|
19
|
+
* expect(deleteButton).toHaveClass('btn')
|
|
20
|
+
* expect(deleteButton).toHaveClass('btn-danger xs')
|
|
21
|
+
* expect(deleteButton).toHaveClass('btn xs btn-danger', {exact: true})
|
|
22
|
+
* expect(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true})
|
|
23
|
+
* expect(noClasses).not.toHaveClass()
|
|
24
|
+
* @see
|
|
25
|
+
* [testing-library/jest-dom#tohaveclass](https://github.com/testing-library/jest-dom#tohaveclass)
|
|
26
|
+
*/
|
|
2
27
|
export declare function toHaveClass(this: MatcherState, htmlElement: Element, ...params: string[]): MatcherResult;
|
|
@@ -21,6 +21,31 @@ function splitClassNames(str) {
|
|
|
21
21
|
function isSubset(subset, superset) {
|
|
22
22
|
return subset.every((item) => superset.includes(item));
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @description
|
|
26
|
+
* Check whether the given element has certain classes within its `class` attribute.
|
|
27
|
+
*
|
|
28
|
+
* You must provide at least one class, unless you are asserting that an element does not have any classes.
|
|
29
|
+
* @example
|
|
30
|
+
* <button
|
|
31
|
+
* data-testid="delete-button"
|
|
32
|
+
* class="btn xs btn-danger"
|
|
33
|
+
* >
|
|
34
|
+
* delete item
|
|
35
|
+
* </button>
|
|
36
|
+
*
|
|
37
|
+
* <div data-testid="no-classes">no classes</div>
|
|
38
|
+
*
|
|
39
|
+
* const deleteButton = getByTestId('delete-button')
|
|
40
|
+
* const noClasses = getByTestId('no-classes')
|
|
41
|
+
* expect(deleteButton).toHaveClass('btn')
|
|
42
|
+
* expect(deleteButton).toHaveClass('btn-danger xs')
|
|
43
|
+
* expect(deleteButton).toHaveClass('btn xs btn-danger', {exact: true})
|
|
44
|
+
* expect(deleteButton).not.toHaveClass('btn xs btn-danger', {exact: true})
|
|
45
|
+
* expect(noClasses).not.toHaveClass()
|
|
46
|
+
* @see
|
|
47
|
+
* [testing-library/jest-dom#tohaveclass](https://github.com/testing-library/jest-dom#tohaveclass)
|
|
48
|
+
*/
|
|
24
49
|
export function toHaveClass(htmlElement, ...params) {
|
|
25
50
|
checkHtmlElement(htmlElement, toHaveClass, this);
|
|
26
51
|
const { expectedClassNames, options } = getExpectedClassNamesAndOptions(params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-have-class.js","sourceRoot":"","sources":["../../src/matchers/to-have-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM1D,SAAS,+BAA+B,CAAC,MAA0C;IAC/E,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;IAC/B,IAAI,kBAA6C,EAAE,OAA2B,CAAC;IAE/E,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAChC,kBAAkB,GAAG,MAAkB,CAAC;QACxC,OAAO,GAAG,SAAS,CAAC;IACxB,CAAC;SAAM,CAAC;QACJ,kBAAkB,GAAI,MAAmB,CAAC,MAAM,CAAC,SAAmB,CAAC,CAAC;QACtE,OAAO,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,eAAe,CAAC,GAA8B;IACnD,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,QAAQ,CAAC,MAAgB,EAAE,QAAkB;IAClD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAA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EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAClB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EACzC,SAAS,EACT,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAC/C,EACD,wBAAwB,EAAE,aAAa,EACvC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAClB,UAAU,EACV,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CACrB,CAAC;YACN,CAAC;SACJ;QACH,CAAC,CAAC;YACI,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK;YAC9C,OAAO,EAAE,GAAG,EAAE,CACV,IAAI,CAAC,KAAK;gBACN,CAAC,CAAC,UAAU,CACN,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,kBAAkB,EAAE,SAAS,EAAE,EAAE,CAAC,EACzD,sCAAsC,EACtC,QAAQ,EACR,UAAU,EACV,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CACrB;gBACH,CAAC,CAAC;oBACI,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,SAAS,CAAC;oBACjD,+CAA+C;iBAClD,CAAC,IAAI,CAAC,IAAI,CAAC;SACzB,CAAC;AACZ,CAAC"}
|
|
@@ -1,4 +1,51 @@
|
|
|
1
1
|
import type { expect } from "vitest";
|
|
2
2
|
import type { MatcherResult, MatcherState } from "./types.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
* since v5.14.1
|
|
6
|
+
* @description
|
|
7
|
+
* Check the accessible description for an element.
|
|
8
|
+
* This allows you to check whether the given element has a description or not.
|
|
9
|
+
*
|
|
10
|
+
* An element gets its description via the
|
|
11
|
+
* [`aria-describedby` attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute).
|
|
12
|
+
* Set this to the `id` of one or more other elements. These elements may be nested
|
|
13
|
+
* inside, be outside, or a sibling of the passed in element.
|
|
14
|
+
*
|
|
15
|
+
* Whitespace is normalized. Using multiple ids will
|
|
16
|
+
* [join the referenced elements’ text content separated by a space](https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description).
|
|
17
|
+
*
|
|
18
|
+
* When a `string` argument is passed through, it will perform a whole
|
|
19
|
+
* case-sensitive match to the description text.
|
|
20
|
+
*
|
|
21
|
+
* To perform a case-insensitive match, you can use a `RegExp` with the `/i`
|
|
22
|
+
* modifier.
|
|
23
|
+
*
|
|
24
|
+
* To perform a partial match, you can pass a `RegExp` or use
|
|
25
|
+
* `expect.stringContaining("partial string")`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* <button aria-label="Close" aria-describedby="description-close">
|
|
29
|
+
* X
|
|
30
|
+
* </button>
|
|
31
|
+
* <div id="description-close">
|
|
32
|
+
* Closing will discard any changes
|
|
33
|
+
* </div>
|
|
34
|
+
*
|
|
35
|
+
* <button>Delete</button>
|
|
36
|
+
*
|
|
37
|
+
* const closeButton = getByRole('button', {name: 'Close'})
|
|
38
|
+
*
|
|
39
|
+
* expect(closeButton).toHaveDescription('Closing will discard any changes')
|
|
40
|
+
* expect(closeButton).toHaveDescription(/will discard/) // to partially match
|
|
41
|
+
* expect(closeButton).toHaveDescription(expect.stringContaining('will discard')) // to partially match
|
|
42
|
+
* expect(closeButton).toHaveDescription(/^closing/i) // to use case-insensitive match
|
|
43
|
+
* expect(closeButton).not.toHaveDescription('Other description')
|
|
44
|
+
*
|
|
45
|
+
* const deleteButton = getByRole('button', {name: 'Delete'})
|
|
46
|
+
* expect(deleteButton).not.toHaveDescription()
|
|
47
|
+
* expect(deleteButton).toHaveDescription('') // Missing or empty description always becomes a blank string
|
|
48
|
+
* @see
|
|
49
|
+
* [testing-library/jest-dom#tohavedescription](https://github.com/testing-library/jest-dom#tohavedescription)
|
|
50
|
+
*/
|
|
4
51
|
export declare function toHaveDescription(this: MatcherState, htmlElement: Element, checkWith?: string | RegExp | typeof expect.stringContaining): MatcherResult;
|