@testing-library/jest-dom
Advanced tools
Comparing version 5.6.0 to 5.7.0
@@ -24,7 +24,23 @@ "use strict"; | ||
const value = tagName === 'select' ? Array.from(htmlElement).filter(option => option.selected).map(option => option.textContent).toString() : htmlElement.value; | ||
const values = getValues(tagName, htmlElement); | ||
const expectedValues = getExpectedValues(expectedValue); | ||
const numberOfMatchesWithValues = getNumberOfMatchesBetweenArrays(values, expectedValues); | ||
const matchedWithAllValues = numberOfMatchesWithValues === values.length; | ||
const matchedWithAllExpectedValues = numberOfMatchesWithValues === expectedValues.length; | ||
return { | ||
pass: value === expectedValue.toString(), | ||
message: () => (0, _utils.getMessage)((0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveDisplayValue`, 'element', ''), `Expected element ${this.isNot ? 'not ' : ''}to have display value`, expectedValue, 'Received', value) | ||
pass: matchedWithAllValues && matchedWithAllExpectedValues, | ||
message: () => (0, _utils.getMessage)((0, _jestMatcherUtils.matcherHint)(`${this.isNot ? '.not' : ''}.toHaveDisplayValue`, 'element', ''), `Expected element ${this.isNot ? 'not ' : ''}to have display value`, expectedValue, 'Received', values) | ||
}; | ||
} | ||
function getValues(tagName, htmlElement) { | ||
return tagName === 'select' ? Array.from(htmlElement).filter(option => option.selected).map(option => option.textContent) : [htmlElement.value]; | ||
} | ||
function getExpectedValues(expectedValue) { | ||
return expectedValue instanceof Array ? expectedValue : [expectedValue]; | ||
} | ||
function getNumberOfMatchesBetweenArrays(arrayBase, array) { | ||
return array.filter(expected => arrayBase.filter(value => (0, _utils.matches)(value, expected)).length).length; | ||
} |
{ | ||
"name": "@testing-library/jest-dom", | ||
"version": "5.6.0", | ||
"version": "5.7.0", | ||
"description": "Custom jest matchers to test the state of the DOM", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -49,2 +49,3 @@ <div align="center"> | ||
- [Installation](#installation) | ||
@@ -785,3 +786,3 @@ - [Usage](#usage) | ||
```typescript | ||
toHaveDisplayValue(value: string | string[]) | ||
toHaveDisplayValue(value: string | RegExp | (string|RegExp)[]) | ||
``` | ||
@@ -831,5 +832,8 @@ | ||
expect(input).toHaveDisplayValue('Luca') | ||
expect(input).toHaveDisplayValue(/Luc/) | ||
expect(textarea).toHaveDisplayValue('An example description here.') | ||
expect(textarea).toHaveDisplayValue(/example/) | ||
expect(selectSingle).toHaveDisplayValue('Select a fruit...') | ||
expect(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado']) | ||
expect(selectSingle).toHaveDisplayValue(/Select/) | ||
expect(selectMultiple).toHaveDisplayValue([/Avocado/, 'Banana']) | ||
``` | ||
@@ -1084,2 +1088,3 @@ | ||
<td align="center"><a href="https://ghuser.io/Ishaan28malik"><img src="https://avatars3.githubusercontent.com/u/27343592?v=4" width="100px;" alt=""/><br /><sub><b>Championrunner</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=Ishaan28malik" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://icing.space/"><img src="https://avatars0.githubusercontent.com/u/2635733?v=4" width="100px;" alt=""/><br /><sub><b>Patrick Smith</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=BurntCaramel" title="Code">💻</a> <a href="https://github.com/testing-library/jest-dom/commits?author=BurntCaramel" title="Tests">⚠️</a> <a href="https://github.com/testing-library/jest-dom/commits?author=BurntCaramel" title="Documentation">📖</a></td> | ||
</tr> | ||
@@ -1086,0 +1091,0 @@ </table> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95189
933
1142