@najemi-software/vitest-dom 0.13.0 → 0.14.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.
Files changed (94) hide show
  1. package/dist/extend-expect.d.ts +1 -3
  2. package/dist/extend-expect.js +2 -6
  3. package/dist/extend-expect.js.map +1 -1
  4. package/dist/matchers/css-parse.d.ts +30 -0
  5. package/dist/matchers/css-parse.js +514 -0
  6. package/dist/matchers/css-parse.js.map +1 -0
  7. package/dist/matchers/to-be-checked.d.ts +2 -0
  8. package/dist/matchers/to-be-checked.js +52 -0
  9. package/dist/matchers/to-be-checked.js.map +1 -0
  10. package/dist/matchers/to-be-disabled.d.ts +3 -0
  11. package/dist/matchers/to-be-disabled.js +74 -0
  12. package/dist/matchers/to-be-disabled.js.map +1 -0
  13. package/dist/matchers/to-be-empty-dom-element.d.ts +2 -0
  14. package/dist/matchers/to-be-empty-dom-element.js +31 -0
  15. package/dist/matchers/to-be-empty-dom-element.js.map +1 -0
  16. package/dist/matchers/to-be-empty.d.ts +3 -0
  17. package/dist/matchers/to-be-empty.js +18 -0
  18. package/dist/matchers/to-be-empty.js.map +1 -0
  19. package/dist/matchers/to-be-in-the-document.d.ts +2 -0
  20. package/dist/matchers/to-be-in-the-document.js +24 -0
  21. package/dist/matchers/to-be-in-the-document.js.map +1 -0
  22. package/dist/matchers/to-be-in-the-dom.d.ts +3 -0
  23. package/dist/matchers/to-be-in-the-dom.js +23 -0
  24. package/dist/matchers/to-be-in-the-dom.js.map +1 -0
  25. package/dist/matchers/to-be-invalid.d.ts +3 -0
  26. package/dist/matchers/to-be-invalid.js +50 -0
  27. package/dist/matchers/to-be-invalid.js.map +1 -0
  28. package/dist/matchers/to-be-partially-checked.d.ts +2 -0
  29. package/dist/matchers/to-be-partially-checked.js +36 -0
  30. package/dist/matchers/to-be-partially-checked.js.map +1 -0
  31. package/dist/matchers/to-be-required.d.ts +2 -0
  32. package/dist/matchers/to-be-required.js +40 -0
  33. package/dist/matchers/to-be-required.js.map +1 -0
  34. package/dist/matchers/to-be-visible.d.ts +2 -0
  35. package/dist/matchers/to-be-visible.js +46 -0
  36. package/dist/matchers/to-be-visible.js.map +1 -0
  37. package/dist/matchers/to-contain-element.d.ts +2 -0
  38. package/dist/matchers/to-contain-element.js +19 -0
  39. package/dist/matchers/to-contain-element.js.map +1 -0
  40. package/dist/matchers/to-contain-html.d.ts +2 -0
  41. package/dist/matchers/to-contain-html.js +25 -0
  42. package/dist/matchers/to-contain-html.js.map +1 -0
  43. package/dist/matchers/to-have-accessible-description.d.ts +4 -0
  44. package/dist/matchers/to-have-accessible-description.js +28 -0
  45. package/dist/matchers/to-have-accessible-description.js.map +1 -0
  46. package/dist/matchers/to-have-accessible-errormessage.d.ts +2 -0
  47. package/dist/matchers/to-have-accessible-errormessage.js +48 -0
  48. package/dist/matchers/to-have-accessible-errormessage.js.map +1 -0
  49. package/dist/matchers/to-have-accessible-name.d.ts +3 -0
  50. package/dist/matchers/to-have-accessible-name.js +27 -0
  51. package/dist/matchers/to-have-accessible-name.js.map +1 -0
  52. package/dist/matchers/to-have-attribute.d.ts +2 -0
  53. package/dist/matchers/to-have-attribute.js +34 -0
  54. package/dist/matchers/to-have-attribute.js.map +1 -0
  55. package/dist/matchers/to-have-class.d.ts +2 -0
  56. package/dist/matchers/to-have-class.js +56 -0
  57. package/dist/matchers/to-have-class.js.map +1 -0
  58. package/dist/matchers/to-have-description.d.ts +4 -0
  59. package/dist/matchers/to-have-description.js +30 -0
  60. package/dist/matchers/to-have-description.js.map +1 -0
  61. package/dist/matchers/to-have-display-value.d.ts +2 -0
  62. package/dist/matchers/to-have-display-value.js +31 -0
  63. package/dist/matchers/to-have-display-value.js.map +1 -0
  64. package/dist/matchers/to-have-errormessage.d.ts +3 -0
  65. package/dist/matchers/to-have-errormessage.js +39 -0
  66. package/dist/matchers/to-have-errormessage.js.map +1 -0
  67. package/dist/matchers/to-have-focus.d.ts +2 -0
  68. package/dist/matchers/to-have-focus.js +22 -0
  69. package/dist/matchers/to-have-focus.js.map +1 -0
  70. package/dist/matchers/to-have-form-values.d.ts +2 -0
  71. package/dist/matchers/to-have-form-values.js +67 -0
  72. package/dist/matchers/to-have-form-values.js.map +1 -0
  73. package/dist/matchers/to-have-style.d.ts +2 -0
  74. package/dist/matchers/to-have-style.js +59 -0
  75. package/dist/matchers/to-have-style.js.map +1 -0
  76. package/dist/matchers/to-have-text-content.d.ts +4 -0
  77. package/dist/matchers/to-have-text-content.js +18 -0
  78. package/dist/matchers/to-have-text-content.js.map +1 -0
  79. package/dist/matchers/to-have-value.d.ts +2 -0
  80. package/dist/matchers/to-have-value.js +27 -0
  81. package/dist/matchers/to-have-value.js.map +1 -0
  82. package/dist/matchers/types.d.ts +13 -0
  83. package/dist/matchers/types.js +2 -0
  84. package/dist/matchers/types.js.map +1 -0
  85. package/dist/matchers/utils.d.ts +43 -0
  86. package/dist/matchers/utils.js +217 -0
  87. package/dist/matchers/utils.js.map +1 -0
  88. package/dist/matchers.d.ts +682 -83
  89. package/dist/matchers.js +25 -56
  90. package/dist/matchers.js.map +1 -1
  91. package/package.json +9 -5
  92. package/dist/chunk-DARZWRGS.js +0 -1546
  93. package/dist/chunk-DARZWRGS.js.map +0 -1
  94. package/dist/matchers-CEKfObS0.d.ts +0 -661
@@ -0,0 +1,27 @@
1
+ import { computeAccessibleName } from "dom-accessibility-api";
2
+ import { checkHtmlElement, getMessage } from "./utils.js";
3
+ export function toHaveAccessibleName(htmlElement, expectedAccessibleName) {
4
+ checkHtmlElement(htmlElement, toHaveAccessibleName, this);
5
+ const actualAccessibleName = computeAccessibleName(htmlElement);
6
+ const missingExpectedValue = arguments.length === 1;
7
+ let pass = false;
8
+ if (missingExpectedValue) {
9
+ // When called without an expected value we only want to validate that the element has an
10
+ // accessible name, whatever it may be.
11
+ pass = actualAccessibleName !== "";
12
+ }
13
+ else {
14
+ pass =
15
+ expectedAccessibleName instanceof RegExp
16
+ ? expectedAccessibleName.test(actualAccessibleName)
17
+ : this.equals(actualAccessibleName, expectedAccessibleName);
18
+ }
19
+ return {
20
+ pass,
21
+ message: () => {
22
+ const to = this.isNot ? "not to" : "to";
23
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.${toHaveAccessibleName.name}`, "element", ""), `Expected element ${to} have accessible name`, expectedAccessibleName, "Received", actualAccessibleName);
24
+ },
25
+ };
26
+ }
27
+ //# sourceMappingURL=to-have-accessible-name.js.map
@@ -0,0 +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,uBAAuB,CAAC;AAI9D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,UAAU,oBAAoB,CAChC,WAAoB,EACpB,sBAAyE;IAEzE,gBAAgB,CAAC,WAAW,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAC1D,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAChE,MAAM,oBAAoB,GAAG,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAEpD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,oBAAoB,EAAE,CAAC;QACvB,yFAAyF;QACzF,uCAAuC;QACvC,IAAI,GAAG,oBAAoB,KAAK,EAAE,CAAC;IACvC,CAAC;SAAM,CAAC;QACJ,IAAI;YACA,sBAAsB,YAAY,MAAM;gBACpC,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,oBAAoB,CAAC;gBACnD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;IACxE,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,oBAAoB,CAAC,IAAI,EAAE,EAC1D,SAAS,EACT,EAAE,CACL,EACD,oBAAoB,EAAE,uBAAuB,EAC7C,sBAAsB,EACtB,UAAU,EACV,oBAAoB,CACvB,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveAttribute(htmlElement: Element, name: string, expectedValue?: unknown): MatcherResult;
@@ -0,0 +1,34 @@
1
+ import { checkHtmlElement, getMessage } from "./utils.js";
2
+ function printAttribute(stringify, name, value) {
3
+ return value === undefined ? name : `${name}=${stringify(value)}`;
4
+ }
5
+ function getAttributeComment(stringify, name, value) {
6
+ return value === undefined
7
+ ? `element.hasAttribute(${stringify(name)})`
8
+ : `element.getAttribute(${stringify(name)}) === ${stringify(value)}`;
9
+ }
10
+ export function toHaveAttribute(htmlElement, name, expectedValue) {
11
+ checkHtmlElement(htmlElement, toHaveAttribute, this);
12
+ const isExpectedValuePresent = expectedValue !== undefined;
13
+ const hasAttribute = htmlElement.hasAttribute(name);
14
+ const receivedValue = htmlElement.getAttribute(name);
15
+ return {
16
+ pass: isExpectedValuePresent
17
+ ? hasAttribute && this.equals(receivedValue, expectedValue)
18
+ : hasAttribute,
19
+ message: () => {
20
+ const to = this.isNot ? "not to" : "to";
21
+ const receivedAttribute = hasAttribute
22
+ ? printAttribute(this.utils.stringify, name, receivedValue)
23
+ : null;
24
+ const matcher = this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveAttribute`, "element", this.utils.printExpected(name), {
25
+ secondArgument: isExpectedValuePresent
26
+ ? this.utils.printExpected(expectedValue)
27
+ : undefined,
28
+ comment: getAttributeComment(this.utils.stringify, name, expectedValue),
29
+ });
30
+ return getMessage(this, matcher, `Expected the element ${to} have attribute`, printAttribute(this.utils.stringify, name, expectedValue), "Received", receivedAttribute);
31
+ },
32
+ };
33
+ }
34
+ //# sourceMappingURL=to-have-attribute.js.map
@@ -0,0 +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,SAAS,EAAE,IAAI,EAAE,KAAK;IAC1C,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,SAAS,EAAE,IAAI,EAAE,KAAK;IAC/C,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,CAAC,WAAoB,EAAE,IAAY,EAAE,aAAuB;IACvF,gBAAgB,CAAC,WAAW,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,sBAAsB,GAAG,aAAa,KAAK,SAAS,CAAC;IAC3D,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO;QACH,IAAI,EAAE,sBAAsB;YACxB,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC;YAC3D,CAAC,CAAC,YAAY;QAClB,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,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"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveClass(htmlElement: Element, ...params: string[]): MatcherResult;
@@ -0,0 +1,56 @@
1
+ import { checkHtmlElement, getMessage } from "./utils.js";
2
+ function getExpectedClassNamesAndOptions(params) {
3
+ const lastParam = params.pop();
4
+ let expectedClassNames, options;
5
+ if (typeof lastParam === "object") {
6
+ expectedClassNames = params;
7
+ options = lastParam;
8
+ }
9
+ else {
10
+ expectedClassNames = params.concat(lastParam);
11
+ options = { exact: false };
12
+ }
13
+ return { expectedClassNames, options };
14
+ }
15
+ function splitClassNames(str) {
16
+ if (!str) {
17
+ return [];
18
+ }
19
+ return str.split(/\s+/).filter((s) => s.length > 0);
20
+ }
21
+ function isSubset(subset, superset) {
22
+ return subset.every((item) => superset.includes(item));
23
+ }
24
+ export function toHaveClass(htmlElement, ...params) {
25
+ checkHtmlElement(htmlElement, toHaveClass, this);
26
+ const { expectedClassNames, options } = getExpectedClassNamesAndOptions(params);
27
+ const received = splitClassNames(htmlElement.getAttribute("class"));
28
+ const expected = expectedClassNames.reduce((acc, className) => acc.concat(splitClassNames(className)), []);
29
+ if (options.exact) {
30
+ return {
31
+ pass: isSubset(expected, received) && expected.length === received.length,
32
+ message: () => {
33
+ const to = this.isNot ? "not to" : "to";
34
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveClass`, "element", this.utils.printExpected(expected.join(" "))), `Expected the element ${to} have EXACTLY defined classes`, expected.join(" "), "Received", received.join(" "));
35
+ },
36
+ };
37
+ }
38
+ return expected.length > 0
39
+ ? {
40
+ pass: isSubset(expected, received),
41
+ message: () => {
42
+ const to = this.isNot ? "not to" : "to";
43
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveClass`, "element", this.utils.printExpected(expected.join(" "))), `Expected the element ${to} have class`, expected.join(" "), "Received", received.join(" "));
44
+ },
45
+ }
46
+ : {
47
+ pass: this.isNot ? received.length > 0 : false,
48
+ message: () => this.isNot
49
+ ? getMessage(this, this.utils.matcherHint(".not.toHaveClass", "element", ""), "Expected the element to have classes", "(none)", "Received", received.join(" "))
50
+ : [
51
+ this.utils.matcherHint(`.toHaveClass`, "element"),
52
+ "At least one expected class must be provided.",
53
+ ].join("\n"),
54
+ };
55
+ }
56
+ //# sourceMappingURL=to-have-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-class.js","sourceRoot":"","sources":["../../src/matchers/to-have-class.ts"],"names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AAK,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"}
@@ -0,0 +1,4 @@
1
+ import type { expect } from "vitest";
2
+ import type { MatcherResult } from "./types.js";
3
+ /** @deprecated */
4
+ export declare function toHaveDescription(htmlElement: Element, checkWith?: string | RegExp | typeof expect.stringContaining): MatcherResult;
@@ -0,0 +1,30 @@
1
+ import { checkHtmlElement, getMessage, normalize, deprecate } from "./utils.js";
2
+ // See algoritm: https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_description
3
+ /** @deprecated */
4
+ export function toHaveDescription(htmlElement, checkWith) {
5
+ deprecate("toHaveDescription", "Please use toHaveAccessibleDescription.");
6
+ checkHtmlElement(htmlElement, toHaveDescription, this);
7
+ const expectsDescription = checkWith !== undefined;
8
+ const descriptionIDRaw = htmlElement.getAttribute("aria-describedby") || "";
9
+ const descriptionIDs = descriptionIDRaw.split(/\s+/).filter(Boolean);
10
+ let description = "";
11
+ if (descriptionIDs.length > 0) {
12
+ const document = htmlElement.ownerDocument;
13
+ const descriptionEls = descriptionIDs
14
+ .map((descriptionID) => document.getElementById(descriptionID))
15
+ .filter(Boolean);
16
+ description = normalize(descriptionEls.map((el) => el.textContent).join(" "));
17
+ }
18
+ return {
19
+ pass: expectsDescription
20
+ ? checkWith instanceof RegExp
21
+ ? checkWith.test(description)
22
+ : this.equals(description, checkWith)
23
+ : Boolean(description),
24
+ message: () => {
25
+ const to = this.isNot ? "not to" : "to";
26
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveDescription`, "element", ""), `Expected the element ${to} have description`, this.utils.printExpected(checkWith), "Received", this.utils.printReceived(description));
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=to-have-description.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-description.js","sourceRoot":"","sources":["../../src/matchers/to-have-description.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEhF,qFAAqF;AACrF,kBAAkB;AAClB,MAAM,UAAU,iBAAiB,CAC7B,WAAoB,EACpB,SAA4D;IAE5D,SAAS,CAAC,mBAAmB,EAAE,yCAAyC,CAAC,CAAC;IAE1E,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAEvD,MAAM,kBAAkB,GAAG,SAAS,KAAK,SAAS,CAAC;IAEnD,MAAM,gBAAgB,GAAG,WAAW,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC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AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveDisplayValue(htmlElement: Element, expectedValue: string | RegExp | Array<string | RegExp>): MatcherResult;
@@ -0,0 +1,31 @@
1
+ import { checkHtmlElement, getMessage } from "./utils.js";
2
+ export function toHaveDisplayValue(htmlElement, expectedValue) {
3
+ checkHtmlElement(htmlElement, toHaveDisplayValue, this);
4
+ const tagName = htmlElement.tagName.toLowerCase();
5
+ if (!["select", "input", "textarea"].includes(tagName)) {
6
+ throw new Error(".toHaveDisplayValue() currently supports only input, textarea or select elements, try with another matcher instead.");
7
+ }
8
+ if (tagName === "input" && ["radio", "checkbox"].includes(htmlElement.type)) {
9
+ throw new Error(`.toHaveDisplayValue() currently does not support input[type="${htmlElement.type}"], try with another matcher instead.`);
10
+ }
11
+ const values = getValues(tagName, htmlElement);
12
+ const expectedValues = getExpectedValues(expectedValue);
13
+ const numberOfMatchesWithValues = expectedValues.filter((expected) => values.some((value) => expected instanceof RegExp ? expected.test(value) : this.equals(value, String(expected)))).length;
14
+ const matchedWithAllValues = numberOfMatchesWithValues === values.length;
15
+ const matchedWithAllExpectedValues = numberOfMatchesWithValues === expectedValues.length;
16
+ return {
17
+ pass: matchedWithAllValues && matchedWithAllExpectedValues,
18
+ message: () => getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveDisplayValue`, "element", ""), `Expected element ${this.isNot ? "not " : ""}to have display value`, expectedValue, "Received", values),
19
+ };
20
+ }
21
+ function getValues(tagName, htmlElement) {
22
+ return tagName === "select"
23
+ ? Array.from(htmlElement)
24
+ .filter((option) => option.selected)
25
+ .map((option) => option.textContent)
26
+ : [htmlElement.value];
27
+ }
28
+ function getExpectedValues(expectedValue) {
29
+ return expectedValue instanceof Array ? expectedValue : [expectedValue];
30
+ }
31
+ //# sourceMappingURL=to-have-display-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-display-value.js","sourceRoot":"","sources":["../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CAAC;IAEzF,OAAO;QACH,IAAI,EAAE,oBAAoB,IAAI,4BAA4B;QAC1D,OAAO,EAAE,GAAG,EAAE,CACV,UAAU,CACN,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,SAAS,EAAE,EAAE,CAAC,EACvF,oBAAoB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,uBAAuB,EACnE,aAAa,EACb,UAAU,EACV,MAAM,CACT;KACR,CAAC;AACN,CAAC;AAED,SAAS,SAAS,CAAC,OAAO,EAAE,WAAW;IACnC,OAAO,OAAO,KAAK,QAAQ;QACvB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;aAClB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;aACnC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;QAC1C,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,iBAAiB,CAAC,aAAa;IACpC,OAAO,aAAa,YAAY,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { expect } from "vitest";
2
+ import type { MatcherResult } from "./types.js";
3
+ export declare function toHaveErrorMessage(htmlElement: Element, checkWith?: string | RegExp | typeof expect.stringContaining): MatcherResult;
@@ -0,0 +1,39 @@
1
+ import { checkHtmlElement, getMessage, normalize } from "./utils.js";
2
+ // See aria-errormessage spec https://www.w3.org/TR/wai-aria-1.2/#aria-errormessage
3
+ export function toHaveErrorMessage(htmlElement, checkWith) {
4
+ checkHtmlElement(htmlElement, toHaveErrorMessage, this);
5
+ if (!htmlElement.hasAttribute("aria-invalid") || htmlElement.getAttribute("aria-invalid") === "false") {
6
+ const not = this.isNot ? ".not" : "";
7
+ return {
8
+ pass: false,
9
+ message: () => {
10
+ return getMessage(this, this.utils.matcherHint(`${not}.toHaveErrorMessage`, "element", ""), `Expected the element to have invalid state indicated by`, 'aria-invalid="true"', "Received", htmlElement.hasAttribute("aria-invalid")
11
+ ? `aria-invalid="${htmlElement.getAttribute("aria-invalid")}"`
12
+ : this.utils.printReceived(""));
13
+ },
14
+ };
15
+ }
16
+ const expectsErrorMessage = checkWith !== undefined;
17
+ const errormessageIDRaw = htmlElement.getAttribute("aria-errormessage") || "";
18
+ const errormessageIDs = errormessageIDRaw.split(/\s+/).filter(Boolean);
19
+ let errormessage = "";
20
+ if (errormessageIDs.length > 0) {
21
+ const document = htmlElement.ownerDocument;
22
+ const errormessageEls = errormessageIDs
23
+ .map((errormessageID) => document.getElementById(errormessageID))
24
+ .filter(Boolean);
25
+ errormessage = normalize(errormessageEls.map((el) => el.textContent).join(" "));
26
+ }
27
+ return {
28
+ pass: expectsErrorMessage
29
+ ? checkWith instanceof RegExp
30
+ ? checkWith.test(errormessage)
31
+ : this.equals(errormessage, checkWith)
32
+ : Boolean(errormessage),
33
+ message: () => {
34
+ const to = this.isNot ? "not to" : "to";
35
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveErrorMessage`, "element", ""), `Expected the element ${to} have error message`, this.utils.printExpected(checkWith), "Received", this.utils.printReceived(errormessage));
36
+ },
37
+ };
38
+ }
39
+ //# sourceMappingURL=to-have-errormessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-errormessage.js","sourceRoot":"","sources":["../../src/matchers/to-have-errormessage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAErE,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAC9B,WAAoB,EACpB,SA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AAC;aAChE,MAAM,CAAC,OAAO,CAAC,CAAC;QAErB,YAAY,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACH,IAAI,EAAE,mBAAmB;YACrB,CAAC,CAAC,SAAS,YAAY,MAAM;gBACzB,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;gBAC9B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;YAC1C,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;QAC3B,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,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,SAAS,EAAE,EAAE,CAAC,EACvF,wBAAwB,EAAE,qBAAqB,EAC/C,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,EACnC,UAAU,EACV,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,CACzC,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveFocus(element: Element): MatcherResult;
@@ -0,0 +1,22 @@
1
+ import { checkHtmlElement } from "./utils.js";
2
+ export function toHaveFocus(element) {
3
+ checkHtmlElement(element, toHaveFocus, this);
4
+ return {
5
+ pass: element.ownerDocument.activeElement === element,
6
+ message: () => {
7
+ return [
8
+ this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveFocus`, "element", ""),
9
+ "",
10
+ ...(this.isNot
11
+ ? ["Received element is focused:", ` ${this.utils.printReceived(element)}`]
12
+ : [
13
+ "Expected element with focus:",
14
+ ` ${this.utils.printExpected(element)}`,
15
+ "Received element with focus:",
16
+ ` ${this.utils.printReceived(element.ownerDocument.activeElement)}`,
17
+ ]),
18
+ ].join("\n");
19
+ },
20
+ };
21
+ }
22
+ //# sourceMappingURL=to-have-focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-focus.js","sourceRoot":"","sources":["../../src/matchers/to-have-focus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,UAAU,WAAW,CAAC,OAAgB;IACxC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAE7C,OAAO;QACH,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,aAAa,KAAK,OAAO;QACrD,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,cAAc,EAAE,SAAS,EAAE,EAAE,CAAC;gBAChF,EAAE;gBACF,GAAG,CAAC,IAAI,CAAC,KAAK;oBACV,CAAC,CAAC,CAAC,8BAA8B,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC5E,CAAC,CAAC;wBACI,8BAA8B;wBAC9B,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;wBACxC,8BAA8B;wBAC9B,KAAK,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE;qBACvE,CAAC;aACX,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveFormValues(this: any, formElement: Element, expectedValues: Record<string, unknown>): MatcherResult;
@@ -0,0 +1,67 @@
1
+ import { isEqualWith, uniq } from "lodash-es";
2
+ import { checkHtmlElement, compareArraysAsSet, getSingleElementValue } from "./utils.js";
3
+ function getMultiElementValue(elements) {
4
+ const types = uniq(elements.map((element) => element.type));
5
+ if (types.length !== 1) {
6
+ throw new Error("Multiple form elements with the same name must be of the same type");
7
+ }
8
+ switch (types[0]) {
9
+ case "radio": {
10
+ const theChosenOne = elements.find((radio) => radio.checked);
11
+ return theChosenOne ? theChosenOne.value : undefined;
12
+ }
13
+ case "checkbox":
14
+ return elements.filter((checkbox) => checkbox.checked).map((checkbox) => checkbox.value);
15
+ default:
16
+ // NOTE: Not even sure this is a valid use case, but just in case...
17
+ return elements.map((element) => element.value);
18
+ }
19
+ }
20
+ function getFormValue(container, name) {
21
+ container.elements;
22
+ const elements = [...container.querySelectorAll("[name]")].filter((element) => element.getAttribute("name") === name);
23
+ if (elements.length === 0) {
24
+ return undefined; // shouldn't happen, but just in case
25
+ }
26
+ switch (elements.length) {
27
+ case 1:
28
+ return getSingleElementValue(elements[0]);
29
+ default:
30
+ return getMultiElementValue(elements);
31
+ }
32
+ }
33
+ // Strips the `[]` suffix off a form value name
34
+ function getPureName(name) {
35
+ return /\[\]$/.test(name) ? name.slice(0, -2) : name;
36
+ }
37
+ function getAllFormValues(container) {
38
+ const names = Array.from(container.elements).map((element) => element.name);
39
+ return names.reduce((obj, name) => ({
40
+ ...obj,
41
+ [getPureName(name)]: getFormValue(container, name),
42
+ }), {});
43
+ }
44
+ export function toHaveFormValues(formElement, expectedValues) {
45
+ checkHtmlElement(formElement, toHaveFormValues, this);
46
+ if (!formElement.elements) {
47
+ // TODO: Change condition to use instanceof against the appropriate element classes instead
48
+ throw new Error("toHaveFormValues must be called on a form or a fieldset");
49
+ }
50
+ const formValues = getAllFormValues(formElement);
51
+ return {
52
+ pass: Object.entries(expectedValues).every(([name, expectedValue]) => isEqualWith(formValues[name], expectedValue, compareArraysAsSet)),
53
+ message: () => {
54
+ const to = this.isNot ? "not to" : "to";
55
+ const matcher = `${this.isNot ? ".not" : ""}.toHaveFormValues`;
56
+ const commonKeyValues = Object.keys(formValues)
57
+ .filter((key) => expectedValues.hasOwnProperty(key))
58
+ .reduce((obj, key) => ({ ...obj, [key]: formValues[key] }), {});
59
+ return [
60
+ this.utils.matcherHint(matcher, "element", ""),
61
+ `Expected the element ${to} have form values`,
62
+ this.utils.diff(expectedValues, commonKeyValues),
63
+ ].join("\n\n");
64
+ },
65
+ };
66
+ }
67
+ //# sourceMappingURL=to-have-form-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-form-values.js","sourceRoot":"","sources":["../../src/matchers/to-have-form-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQzF,SAAS,oBAAoB,CAAC,QAA4B;IACtD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAC1F,CAAC;IACD,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,KAAK,OAAO,CAAC,CAAC,CAAC;YACX,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7D,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,C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AAC;iBACnD,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACpE,OAAO;gBACH,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC;gBAC9C,wBAAwB,EAAE,mBAAmB;gBAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC;aACnD,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveStyle(htmlElement: Element, css: string | Record<string, unknown>): MatcherResult;
@@ -0,0 +1,59 @@
1
+ import chalk from "chalk";
2
+ import { checkHtmlElement, parseCSS } from "./utils.js";
3
+ function getStyleDeclaration(document, css) {
4
+ const styles = {};
5
+ // The next block is necessary to normalize colors
6
+ const copy = document.createElement("div");
7
+ Object.keys(css).forEach((property) => {
8
+ copy.style[property] = css[property];
9
+ // Number values default to px. jsdom's CSSOM did this coercion
10
+ // itself; happy-dom rejects bare numbers, so retry with px appended.
11
+ if (copy.style[property] === "" && typeof css[property] === "number") {
12
+ copy.style[property] = `${css[property]}px`;
13
+ }
14
+ // Fall back to the raw value for properties the style declaration
15
+ // swallows instead of echoing back (happy-dom does this for unknown
16
+ // and custom properties); otherwise expected `undefined` would
17
+ // spuriously match any element missing that property.
18
+ styles[property] = copy.style[property] || css[property];
19
+ });
20
+ return styles;
21
+ }
22
+ function isSubset(styles, computedStyle) {
23
+ return (!!Object.keys(styles).length &&
24
+ Object.entries(styles).every(([prop, value]) => computedStyle[prop] === value || computedStyle.getPropertyValue(prop.toLowerCase()) === value));
25
+ }
26
+ function printoutStyles(styles) {
27
+ return Object.keys(styles)
28
+ .sort()
29
+ .map((prop) => `${prop}: ${styles[prop]};`)
30
+ .join("\n");
31
+ }
32
+ // Highlights only style rules that were expected but were not found in the
33
+ // received computed styles
34
+ function expectedDiff(diffFn, expected, computedStyles) {
35
+ const received = Array.from(computedStyles)
36
+ .filter((prop) => expected[prop] !== undefined)
37
+ .reduce((obj, prop) => Object.assign(obj, { [prop]: computedStyles.getPropertyValue(prop) }), {});
38
+ const diffOutput = diffFn(printoutStyles(expected), printoutStyles(received));
39
+ // Remove the "+ Received" annotation because this is a one-way diff
40
+ return diffOutput.replace(`${chalk.red("+ Received")}\n`, "");
41
+ }
42
+ export function toHaveStyle(htmlElement, css) {
43
+ checkHtmlElement(htmlElement, toHaveStyle, this);
44
+ const parsedCSS = typeof css === "object" ? css : parseCSS(css, toHaveStyle, this);
45
+ const { getComputedStyle } = htmlElement.ownerDocument.defaultView;
46
+ const expected = getStyleDeclaration(htmlElement.ownerDocument, parsedCSS);
47
+ const received = getComputedStyle(htmlElement);
48
+ return {
49
+ pass: isSubset(expected, received),
50
+ message: () => {
51
+ const matcher = `${this.isNot ? ".not" : ""}.toHaveStyle`;
52
+ return [
53
+ this.utils.matcherHint(matcher, "element", ""),
54
+ expectedDiff(this.utils.diff, expected, received),
55
+ ].join("\n\n");
56
+ },
57
+ };
58
+ }
59
+ //# sourceMappingURL=to-have-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-style.js","sourceRoot":"","sources":["../../src/matchers/to-have-style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAExD,SAAS,mBAAmB,CAAC,QAAQ,EAAE,GAAG;IACtC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,kDAAkD;IAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,CAAC,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,CAAC;QAClC,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC;YAC1D,OAAO;gBACH,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC;gBAC9C,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC;aACpD,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveTextContent(node: Element, checkWith: string | RegExp, options?: {
3
+ normalizeWhitespace: boolean;
4
+ }): MatcherResult;
@@ -0,0 +1,18 @@
1
+ import { getMessage, checkNode, matches, normalize } from "./utils.js";
2
+ export function toHaveTextContent(node, checkWith, options = { normalizeWhitespace: true }) {
3
+ checkNode(node, toHaveTextContent, this);
4
+ const textContent = options.normalizeWhitespace
5
+ ? normalize(node.textContent)
6
+ : node.textContent.replace(/\u00a0/g, " "); // Replace &nbsp; with normal spaces
7
+ const checkingWithEmptyString = textContent !== "" && checkWith === "";
8
+ return {
9
+ pass: !checkingWithEmptyString && matches(textContent, checkWith),
10
+ message: () => {
11
+ const to = this.isNot ? "not to" : "to";
12
+ return getMessage(this, this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveTextContent`, "element", ""), checkingWithEmptyString
13
+ ? `Checking with empty string will always match, use .toBeEmptyDOMElement() instead`
14
+ : `Expected element ${to} have text content`, checkWith, "Received", textContent);
15
+ },
16
+ };
17
+ }
18
+ //# sourceMappingURL=to-have-text-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-text-content.js","sourceRoot":"","sources":["../../src/matchers/to-have-text-content.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,UAAU,iBAAiB,CAC7B,IAAa,EACb,SAA0B,EAC1B,UAA4C,EAAE,mBAAmB,EAAE,IAAI,EAAE;IAEzE,SAAS,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAEzC,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB;QAC3C,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC;QAC7B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,oCAAoC;IAEpF,MAAM,uBAAuB,GAAG,WAAW,KAAK,EAAE,IAAI,SAAS,KAAK,EAAE,CAAC;IAEvE,OAAO;QACH,IAAI,EAAE,CAAC,uBAAuB,IAAI,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;QACjE,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,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,SAAS,EAAE,EAAE,CAAC,EACtF,uBAAuB;gBACnB,CAAC,CAAC,kFAAkF;gBACpF,CAAC,CAAC,oBAAoB,EAAE,oBAAoB,EAChD,SAAS,EACT,UAAU,EACV,WAAW,CACd,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MatcherResult } from "./types.js";
2
+ export declare function toHaveValue(htmlElement: Element, expectedValue?: string | string[] | number | null): MatcherResult;
@@ -0,0 +1,27 @@
1
+ import { isEqualWith } from "lodash-es";
2
+ import { checkHtmlElement, compareArraysAsSet, getMessage, getSingleElementValue } from "./utils.js";
3
+ export function toHaveValue(htmlElement, expectedValue) {
4
+ checkHtmlElement(htmlElement, toHaveValue, this);
5
+ if (htmlElement.tagName.toLowerCase() === "input" && ["checkbox", "radio"].includes(htmlElement.type)) {
6
+ throw new Error("input with type=checkbox or type=radio cannot be used with .toHaveValue(). Use .toBeChecked() for type=checkbox or .toHaveFormValues() instead");
7
+ }
8
+ const receivedValue = getSingleElementValue(htmlElement);
9
+ const expectsValue = expectedValue !== undefined;
10
+ let expectedTypedValue = expectedValue;
11
+ let receivedTypedValue = receivedValue;
12
+ if (expectedValue == receivedValue && expectedValue !== receivedValue) {
13
+ expectedTypedValue = `${expectedValue} (${typeof expectedValue})`;
14
+ receivedTypedValue = `${receivedValue} (${typeof receivedValue})`;
15
+ }
16
+ return {
17
+ pass: expectsValue
18
+ ? isEqualWith(receivedValue, expectedValue, compareArraysAsSet)
19
+ : Boolean(receivedValue),
20
+ message: () => {
21
+ const to = this.isNot ? "not to" : "to";
22
+ const matcher = this.utils.matcherHint(`${this.isNot ? ".not" : ""}.toHaveValue`, "element", expectedValue);
23
+ return getMessage(this, matcher, `Expected the element ${to} have value`, expectsValue ? expectedTypedValue : "(any)", "Received", receivedTypedValue);
24
+ },
25
+ };
26
+ }
27
+ //# sourceMappingURL=to-have-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-have-value.js","sourceRoot":"","sources":["../../src/matchers/to-have-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAErG,MAAM,UAAU,WAAW,CACvB,WAAoB,EACpB,aAAiD;IAEjD,gBAAgB,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAEjD,IAAI,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO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
2
+ export interface MatcherResult {
3
+ pass: boolean;
4
+ message(): string;
5
+ actual?: unknown;
6
+ expected?: unknown;
7
+ }
8
+ export type ExpectationResult = MatcherResult | Promise<MatcherResult>;
9
+ export interface MatcherFn<T extends MatcherState = MatcherState> {
10
+ (this: T, received: any, expected: any, options?: any): ExpectationResult;
11
+ }
12
+ export type MatcherState = ReturnType<ExpectStatic["getState"]>;
13
+ export type InferredMatcher<T extends MatcherFn, R> = (...args: T extends (first: any, ...rest: infer P) => any ? P : never) => R;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/matchers/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,43 @@
1
+ import type { MatcherFn, MatcherState } from "./types.js";
2
+ declare class GenericTypeError<State extends MatcherState> extends Error {
3
+ constructor(expectedString: string, received: HTMLElement, matcherFn: MatcherFn<State>, context: State);
4
+ }
5
+ declare class HtmlElementTypeError<State extends MatcherState = any> extends GenericTypeError<State> {
6
+ constructor(element: HTMLElement, matcherFn: MatcherFn<State>, context: State);
7
+ }
8
+ declare class NodeTypeError<State extends MatcherState = any> extends GenericTypeError<State> {
9
+ constructor(element: HTMLElement, matcherFn: MatcherFn<State>, context: State);
10
+ }
11
+ declare function checkNode<State extends MatcherState = any>(node: HTMLElement, matcherFn: MatcherFn, context: State): void;
12
+ declare function checkHtmlElement<State extends MatcherState>(htmlElement: HTMLElement, matcher: MatcherFn<State>, context: State): void;
13
+ declare function parseCSS<State extends MatcherState>(css: string, matcherFn: MatcherFn, context: State): any;
14
+ declare function getMessage(context: MatcherState, matcher: string, expectedLabel: string, expectedValue: any, receivedLabel: string, receivedValue: any): string;
15
+ declare function matches(textToMatch: string, matcher: MatcherFn): boolean;
16
+ declare function deprecate(name: string, replacementText: string): void;
17
+ declare function normalize(text: string): string;
18
+ declare function getTag(element: Element): string;
19
+ declare function getSelectValue({ multiple, options }: HTMLSelectElement): any;
20
+ declare function getInputValue(inputElement: HTMLInputElement): string | number | boolean;
21
+ declare function getSingleElementValue(element: undefined | null): undefined;
22
+ declare function getSingleElementValue(element: HTMLInputElement): ReturnType<typeof getInputValue>;
23
+ declare function getSingleElementValue(element: HTMLSelectElement): ReturnType<typeof getSelectValue>;
24
+ declare function getSingleElementValue(element: HTMLMeterElement | HTMLProgressElement): number;
25
+ declare function getSingleElementValue(element: HTMLButtonElement | HTMLDataElement | HTMLOptionElement | HTMLOutputElement | HTMLTextAreaElement): string;
26
+ declare function getSingleElementValue(element: Element): undefined | string | string[] | number | boolean | null;
27
+ declare function compareArraysAsSet(a: unknown, b: unknown): boolean;
28
+ declare function toSentence(array: string[], { wordConnector, lastWordConnector }?: {
29
+ wordConnector?: string;
30
+ lastWordConnector?: string;
31
+ }): string;
32
+ export { HtmlElementTypeError, NodeTypeError, checkHtmlElement, checkNode, parseCSS, deprecate, getMessage, matches, normalize, getTag, getSingleElementValue, compareArraysAsSet, toSentence, };
33
+ /**
34
+ * https://github.com/jestjs/jest/blob/main/packages/jest-get-type/src/index.ts
35
+ *
36
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
37
+ *
38
+ * This source code is licensed under the MIT license found in the
39
+ * LICENSE file in the root directory of this source tree.
40
+ */
41
+ type ValueType = "array" | "bigint" | "boolean" | "function" | "null" | "number" | "object" | "regexp" | "map" | "set" | "date" | "string" | "symbol" | "undefined";
42
+ export declare function getType(value: unknown): ValueType;
43
+ export declare const isPrimitive: (value: unknown) => boolean;