Skip to content

Commit

Permalink
Update dependency @testing-library/jest-dom to v5.14.1 (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Caleb Eby <caleb.eby01@gmail.com>
  • Loading branch information
3 people authored Jul 8, 2021
1 parent 0e65178 commit 69fd00b
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-pumpkins-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pleasantest': minor
---

Remove toHaveDescription, toBeInTheDOM, and toBeEmpty (they are deprecated by jest-dom)
5 changes: 5 additions & 0 deletions .changeset/purple-colts-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pleasantest': minor
---

Add toHaveAccessibleDescription and toHaveAccessibleName from jest-dom matchers
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ Pleasantest adds [`jest-dom`'s matchers](https://github.com/testing-library/jest

List of matchers:

[`toBeDisabled`](https://github.com/testing-library/jest-dom#tobedisabled), [`toBeEnabled`](https://github.com/testing-library/jest-dom#tobeenabled), [`toBeEmpty`](https://github.com/testing-library/jest-dom#tobeempty), [`toBeEmptyDOMElement`](https://github.com/testing-library/jest-dom#tobeemptydomelement), [`toBeInTheDocument`](https://github.com/testing-library/jest-dom#tobeinthedocument), [`toBeInvalid`](https://github.com/testing-library/jest-dom#tobeinvalid), [`toBeRequired`](https://github.com/testing-library/jest-dom#toberequired), [`toBeValid`](https://github.com/testing-library/jest-dom#tobevalid), [`toBeVisible`](https://github.com/testing-library/jest-dom#tobevisible), [`toContainElement`](https://github.com/testing-library/jest-dom#tocontainelement), [`toContainHTML`](https://github.com/testing-library/jest-dom#tocontainhtml), [`toHaveAttribute`](https://github.com/testing-library/jest-dom#tohaveattribute), [`toHaveClass`](https://github.com/testing-library/jest-dom#tohaveclass), [`toHaveFocus`](https://github.com/testing-library/jest-dom#tohavefocus), [`toHaveFormValues`](https://github.com/testing-library/jest-dom#tohaveformvalues), [`toHaveStyle`](https://github.com/testing-library/jest-dom#tohavestyle), [`toHaveTextContent`](https://github.com/testing-library/jest-dom#tohavetextcontent), [`toHaveValue`](https://github.com/testing-library/jest-dom#tohavevalue), [`toHaveDisplayValue`](https://github.com/testing-library/jest-dom#tohavedisplayvalue), [`toBeChecked`](https://github.com/testing-library/jest-dom#tobechecked), [`toBePartiallyChecked`](https://github.com/testing-library/jest-dom#tobepartiallychecked), [`toHaveDescription`](https://github.com/testing-library/jest-dom#tohavedescription), [`toHaveErrorMessage`](https://github.com/testing-library/jest-dom#tohaveerrormessage).
[`toBeDisabled`](https://github.com/testing-library/jest-dom#tobedisabled), [`toBeEnabled`](https://github.com/testing-library/jest-dom#tobeenabled), [`toBeEmptyDOMElement`](https://github.com/testing-library/jest-dom#tobeemptydomelement), [`toBeInTheDocument`](https://github.com/testing-library/jest-dom#tobeinthedocument), [`toBeInvalid`](https://github.com/testing-library/jest-dom#tobeinvalid), [`toBeRequired`](https://github.com/testing-library/jest-dom#toberequired), [`toBeValid`](https://github.com/testing-library/jest-dom#tobevalid), [`toBeVisible`](https://github.com/testing-library/jest-dom#tobevisible), [`toContainElement`](https://github.com/testing-library/jest-dom#tocontainelement), [`toContainHTML`](https://github.com/testing-library/jest-dom#tocontainhtml), [`toHaveAccessibleDescription`](https://github.com/testing-library/jest-dom#tohaveaccessibledescription), [`toHaveAccessibleName`](https://github.com/testing-library/jest-dom#tohaveaccessiblename), [`toHaveAttribute`](https://github.com/testing-library/jest-dom#tohaveattribute), [`toHaveClass`](https://github.com/testing-library/jest-dom#tohaveclass), [`toHaveFocus`](https://github.com/testing-library/jest-dom#tohavefocus), [`toHaveFormValues`](https://github.com/testing-library/jest-dom#tohaveformvalues), [`toHaveStyle`](https://github.com/testing-library/jest-dom#tohavestyle), [`toHaveTextContent`](https://github.com/testing-library/jest-dom#tohavetextcontent), [`toHaveValue`](https://github.com/testing-library/jest-dom#tohavevalue), [`toHaveDisplayValue`](https://github.com/testing-library/jest-dom#tohavedisplayvalue), [`toBeChecked`](https://github.com/testing-library/jest-dom#tobechecked), [`toBePartiallyChecked`](https://github.com/testing-library/jest-dom#tobepartiallychecked), [`toHaveErrorMessage`](https://github.com/testing-library/jest-dom#tohaveerrormessage).
.

> :warning: **Don't forget to `await` matchers!** This is necessary because the matchers execute in the browser. If you forget, your matchers may execute after your test finishes, and you may get obscure errors.
Expand Down
16 changes: 9 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@rollup/plugin-babel": "5.3.0",
"@rollup/plugin-node-resolve": "13.0.0",
"@testing-library/dom": "8.1.0",
"@testing-library/jest-dom": "5.13.0",
"@testing-library/jest-dom": "5.14.1",
"@types/jest": "26.0.23",
"@types/node": "16.0.0",
"@types/polka": "0.5.2",
Expand Down
24 changes: 15 additions & 9 deletions src/extend-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
} from './utils';

const methods = [
'toBeInTheDOM',
'toBeInTheDocument',
'toBeEmpty',
'toBeEmptyDOMElement',
'toContainElement',
'toContainHTML',
'toHaveAccessibleDescription',
'toHaveAccessibleName',
'toHaveTextContent',
'toHaveAttribute',
'toHaveClass',
Expand All @@ -31,7 +31,6 @@ const methods = [
'toHaveDisplayValue',
'toBeChecked',
'toBePartiallyChecked',
'toHaveDescription',
'toHaveErrorMessage',
] as const;

Expand Down Expand Up @@ -319,6 +318,19 @@ declare global {
* https://github.com/testing-library/jest-dom#tocontainhtml
*/
toContainHTML(html: string): Promise<R>;
/**
* Assert that an element has the expected [accessible description](https://www.w3.org/TR/accname-1.1/#dfn-accessible-description).
* You can pass the exact string, or you can make a partial match passing a regular expression
* https://github.com/testing-library/jest-dom#tohaveaccessibledescription
*/
toHaveAccessibleDescription(text?: string | RegExp): Promise<R>;
/**
* Assert that an element has the expected [accessible description](https://www.w3.org/TR/accname-1.1/#dfn-accessible-name).
* It is useful, for instance, to assert that form elements and buttons are properly labelled.
* You can pass the exact string, or you can make a partial match passing a regular expression
* https://github.com/testing-library/jest-dom#tohaveaccessibledescription
*/
toHaveAccessibleName(text?: string | RegExp): Promise<R>;
/**
* Check whether the given element has an attribute or not.
* You can also optionally check that the attribute has a specific expected value
Expand Down Expand Up @@ -390,12 +402,6 @@ declare global {
*/
toBePartiallyChecked(): Promise<R>;

/**
* Check whether the given element has a description (via aria-describedby)
* https://github.com/testing-library/jest-dom#tohavedescription
*/
toHaveDescription(text?: string | RegExp): Promise<R>;

/**
* Check whether the given element has an ARIA error message (via aria-errormessage)
* https://github.com/testing-library/jest-dom#tohaveerrormessage
Expand Down
60 changes: 60 additions & 0 deletions tests/jest-dom-matchers/toHaveAccessibleDescription.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { withBrowser } from 'pleasantest';

test(
'toHaveAccessibleDescription',
withBrowser(async ({ screen, utils }) => {
await utils.injectHTML(`
<a
data-testid="link"
href="/"
aria-label="Home page"
title="A link to start over"
>Start</a
>
<a data-testid="extra-link" href="/about" aria-label="About page">About</a>
<img src="" data-testid="avatar" alt="User profile pic" />
<img
src=""
data-testid="logo"
alt="Company logo"
aria-describedby="t1"
/>
<span id="t1" role="presentation">The logo of Our Company</span>
`);

const link = await screen.getByTestId('link');
await expect(link).toHaveAccessibleDescription();
await expect(expect(link).not.toHaveAccessibleDescription()).rejects
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).not.toHaveAccessibleDescription()
Expected element not to have accessible description:
 null
Received:
 A link to start over"
`);
await expect(link).toHaveAccessibleDescription('A link to start over');
await expect(link).not.toHaveAccessibleDescription('Home page');
await expect(expect(link).toHaveAccessibleDescription('Home page')).rejects
.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toHaveAccessibleDescription()
Expected element to have accessible description:
 Home page
Received:
 A link to start over"
`);

await expect(
await screen.getByTestId('extra-link'),
).not.toHaveAccessibleDescription();

await expect(
await screen.getByTestId('avatar'),
).not.toHaveAccessibleDescription();

const logo = await screen.getByTestId('logo');
await expect(logo).not.toHaveAccessibleDescription('Company logo');
await expect(logo).toHaveAccessibleDescription('The logo of Our Company');
}),
);
84 changes: 84 additions & 0 deletions tests/jest-dom-matchers/toHaveAccessibleName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { withBrowser } from 'pleasantest';

test(
'toHaveAccessibleName',
withBrowser(async ({ screen, utils }) => {
await utils.injectHTML(`
<img data-testid="img-alt" src="" alt="Test alt" />
<img data-testid="img-empty-alt" src="" alt="" />
<svg data-testid="svg-title"><title>Test title</title></svg>
<button data-testid="button-img-alt"><img src="" alt="Test" /></button>
<p><img data-testid="img-paragraph" src="" alt="" /> Test content</p>
<button data-testid="svg-button"><svg><title>Test</title></svg></p>
<div><svg data-testid="svg-without-title"></svg></div>
<input data-testid="input-title" title="test" />
`);

await expect(await screen.getByTestId('img-alt')).toHaveAccessibleName(
'Test alt',
);

await expect(await screen.getByTestId('img-alt')).not.toHaveAccessibleName(
'not test alt',
);
await expect(
expect(await screen.getByTestId('img-alt')).toHaveAccessibleName(
'not test alt',
),
).rejects.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toHaveAccessibleName()
Expected element to have accessible name:
 not test alt
Received:
 Test alt"
`);

await expect(
expect(await screen.getByTestId('img-empty-alt')).toHaveAccessibleName(),
).rejects.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toHaveAccessibleName()
Expected element to have accessible name:
 null
Received:
"
`);

await expect(
await screen.getByTestId('img-empty-alt'),
).not.toHaveAccessibleName();
await expect(
expect(await screen.getByTestId('img-empty-alt')).toHaveAccessibleName(),
).rejects.toThrowErrorMatchingInlineSnapshot(`
"expect(element).toHaveAccessibleName()
Expected element to have accessible name:
 null
Received:
"
`);

await expect(await screen.getByTestId('svg-title')).toHaveAccessibleName(
'Test title',
);

await expect(
await screen.getByTestId('button-img-alt'),
).toHaveAccessibleName();

await expect(
await screen.getByTestId('img-paragraph'),
).not.toHaveAccessibleName();

await expect(await screen.getByTestId('svg-button')).toHaveAccessibleName();

await expect(
await screen.getByTestId('svg-without-title'),
).not.toHaveAccessibleName();

await expect(
await screen.getByTestId('input-title'),
).toHaveAccessibleName();
}),
);
57 changes: 0 additions & 57 deletions tests/jest-dom-matchers/toHaveDescription.test.ts

This file was deleted.

0 comments on commit 69fd00b

Please sign in to comment.