diff --git a/types/testing-library__jest-dom/index.d.ts b/types/testing-library__jest-dom/index.d.ts index ba09a068368632..406563f5992517 100644 --- a/types/testing-library__jest-dom/index.d.ts +++ b/types/testing-library__jest-dom/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for @testing-library/jest-dom 5.6 +// Type definitions for @testing-library/jest-dom 5.7 // Project: https://github.com/testing-library/jest-dom // Definitions by: Ernesto GarcĂ­a // John Gozde @@ -251,6 +251,48 @@ declare namespace jest { * [testing-library/jest-dom#tohaveclass](https:github.com/testing-library/jest-dom#tohaveclass) */ toHaveClass(...classNames: string[]): R; + /** + * @description + * This allows you to check whether the given form element has the specified displayed value (the one the + * end user will see). It accepts , + * + * + * + * + * + * + * + * const input = screen.getByLabelText('First name') + * const textarea = screen.getByLabelText('Description') + * const selectSingle = screen.getByLabelText('Fruit') + * const selectMultiple = screen.getByLabelText('Fruits') + * + * expect(input).toHaveDisplayValue('Luca') + * expect(textarea).toHaveDisplayValue('An example description here.') + * expect(selectSingle).toHaveDisplayValue('Select a fruit...') + * expect(selectMultiple).toHaveDisplayValue(['Banana', 'Avocado']) + * + * @see + * [testing-library/jest-dom#tohavedisplayvalue](https:github.com/testing-library/jest-dom#tohavedisplayvalue) + */ + toHaveDisplayValue(value: string | RegExp | Array): R; /** * @description * Assert whether an element has focus or not. diff --git a/types/testing-library__jest-dom/test/testing-library__jest-dom-global-tests.ts b/types/testing-library__jest-dom/test/testing-library__jest-dom-global-tests.ts index 5aa585ed91a17b..0835e85c566dfd 100644 --- a/types/testing-library__jest-dom/test/testing-library__jest-dom-global-tests.ts +++ b/types/testing-library__jest-dom/test/testing-library__jest-dom-global-tests.ts @@ -19,6 +19,10 @@ expect(element).toHaveAttribute('attr', 'yes'); expect(element).toHaveClass(); expect(element).toHaveClass('cls1'); expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4'); +expect(element).toHaveDisplayValue('str'); +expect(element).toHaveDisplayValue(['str1', 'str2']); +expect(element).toHaveDisplayValue(/str/); +expect(element).toHaveDisplayValue([/str1/, 'str2']); expect(element).toHaveFocus(); expect(element).toHaveFormValues({ foo: 'bar', baz: 1 }); expect(element).toHaveStyle('display: block'); @@ -57,6 +61,10 @@ expect(element).not.toHaveAttribute('attr', 'yes'); expect(element).not.toHaveClass(); expect(element).not.toHaveClass('cls1'); expect(element).not.toHaveClass('cls1', 'cls2', 'cls3', 'cls4'); +expect(element).not.toHaveDisplayValue('str'); +expect(element).not.toHaveDisplayValue(['str1', 'str2']); +expect(element).not.toHaveDisplayValue(/str/); +expect(element).not.toHaveDisplayValue([/str1/, 'str2']); expect(element).not.toHaveFocus(); expect(element).not.toHaveFormValues({ foo: 'bar', baz: 1 }); expect(element).not.toHaveStyle('display: block');