Skip to content

Support unenclosed inner text for details elements in to be visible main rebased #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,62 @@
"contributions": [
"doc"
]
},
{
"login": "MatanBobi",
"name": "Matan Borenkraout",
"avatar_url": "https://avatars.githubusercontent.com/u/12711091?v=4",
"profile": "https://matan.io",
"contributions": [
"platform"
]
},
{
"login": "yannbf",
"name": "Yann Braga",
"avatar_url": "https://avatars.githubusercontent.com/u/1671563?v=4",
"profile": "https://github.com/yannbf",
"contributions": [
"code"
]
},
{
"login": "IanVS",
"name": "Ian VanSchooten",
"avatar_url": "https://avatars.githubusercontent.com/u/4616705?v=4",
"profile": "https://github.com/IanVS",
"contributions": [
"code"
]
},
{
"login": "cbroeren",
"name": "Chantal Broeren",
"avatar_url": "https://avatars.githubusercontent.com/u/7499806?v=4",
"profile": "http://chantalbroeren.nl",
"contributions": [
"doc"
]
},
{
"login": "astorije",
"name": "Jérémie Astori",
"avatar_url": "https://avatars.githubusercontent.com/u/113730?v=4",
"profile": "https://jeremie.astori.fr",
"contributions": [
"code",
"ideas"
]
},
{
"login": "ashleyryan",
"name": "Ashley Ryan",
"avatar_url": "https://avatars.githubusercontent.com/u/9469374?v=4",
"profile": "https://github.com/ashleyryan",
"contributions": [
"code",
"ideas"
]
}
],
"repoHost": "https://github.com",
Expand Down
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
registry=http://registry.npmjs.org/
registry=https://registry.npmjs.org/
package-lock=false
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ clear to read and to maintain.
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Installation](#installation)
- [Usage](#usage)
- [With TypeScript](#with-typescript)
Expand Down Expand Up @@ -160,7 +159,8 @@ toBeDisabled()
This allows you to check whether an element is disabled from the user's
perspective. According to the specification, the following elements can be
[disabled](https://html.spec.whatwg.org/multipage/semantics-other.html#disabled-elements):
`button`, `input`, `select`, `textarea`, `optgroup`, `option`, `fieldset`.
`button`, `input`, `select`, `textarea`, `optgroup`, `option`, `fieldset`, and
custom elements.

This custom matcher considers an element as disabled if the element is among the
types of elements that can be disabled (listed above), and the `disabled`
Expand Down Expand Up @@ -423,6 +423,14 @@ An element is visible if **all** the following conditions are met:
</div>
<div data-testid="visible">Visible Example</div>
<div data-testid="hidden-attribute" hidden>Hidden Attribute Example</div>
<details>
<summary>Title of hidden text</summary>
Hidden Details Example
</details>
<details open>
<summary>Title of visible text</summary>
<div>Visible Details Example</div>
</details>
```

```javascript
Expand All @@ -432,6 +440,8 @@ expect(getByText('Display None Example')).not.toBeVisible()
expect(getByText('Hidden Parent Example')).not.toBeVisible()
expect(getByText('Visible Example')).toBeVisible()
expect(getByText('Hidden Attribute Example')).not.toBeVisible()
expect(getByText('Hidden Details Example')).not.toBeVisible()
expect(getByText('Visible Details Example')).toBeVisible()
```

<hr />
Expand Down Expand Up @@ -890,7 +900,7 @@ const selectInput = getByTestId('select-number')
expect(textInput).toHaveValue('text')
expect(numberInput).toHaveValue(5)
expect(emptyInput).not.toHaveValue()
expect(selectInput).not.toHaveValue(['second', 'third'])
expect(selectInput).toHaveValue(['second', 'third'])
```

<hr />
Expand Down Expand Up @@ -1203,12 +1213,8 @@ To perform a partial match, you can pass a `RegExp` or use
#### Examples

```html
<button aria-label="Close" aria-describedby="description-close">
X
</button>
<div id="description-close">
Closing will discard any changes
</div>
<button aria-label="Close" aria-describedby="description-close">X</button>
<div id="description-close">Closing will discard any changes</div>

<button>Delete</button>
```
Expand Down Expand Up @@ -1354,6 +1360,12 @@ Thanks goes to these people ([emoji key][emojis]):
</tr>
<tr>
<td align="center"><a href="http://tu4mo.com"><img src="https://avatars.githubusercontent.com/u/16735302?v=4?s=100" width="100px;" alt=""/><br /><sub><b>tu4mo</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=tu4mo" title="Documentation">📖</a></td>
<td align="center"><a href="https://matan.io"><img src="https://avatars.githubusercontent.com/u/12711091?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Matan Borenkraout</b></sub></a><br /><a href="#platform-MatanBobi" title="Packaging/porting to new platform">📦</a></td>
<td align="center"><a href="https://github.com/yannbf"><img src="https://avatars.githubusercontent.com/u/1671563?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Yann Braga</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=yannbf" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/IanVS"><img src="https://avatars.githubusercontent.com/u/4616705?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ian VanSchooten</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=IanVS" title="Code">💻</a></td>
<td align="center"><a href="http://chantalbroeren.nl"><img src="https://avatars.githubusercontent.com/u/7499806?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chantal Broeren</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=cbroeren" title="Documentation">📖</a></td>
<td align="center"><a href="https://jeremie.astori.fr"><img src="https://avatars.githubusercontent.com/u/113730?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jérémie Astori</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=astorije" title="Code">💻</a> <a href="#ideas-astorije" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/ashleyryan"><img src="https://avatars.githubusercontent.com/u/9469374?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ashley Ryan</b></sub></a><br /><a href="https://github.com/testing-library/jest-dom/commits?author=ashleyryan" title="Code">💻</a> <a href="#ideas-ashleyryan" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@babel/runtime": "^7.9.2",
"@types/testing-library__jest-dom": "^5.9.1",
"aria-query": "^4.2.2",
"aria-query": "^5.0.0",
"chalk": "^3.0.0",
"css": "^3.0.0",
"css.escape": "^1.5.1",
Expand Down
42 changes: 42 additions & 0 deletions src/__tests__/to-be-disabled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import document from './helpers/document'
import {render} from './helpers/test-utils'

const window = document.defaultView

window.customElements.define(
'custom-element',
class extends window.HTMLElement {},
)

test('.toBeDisabled', () => {
const {queryByTestId} = render(`
<div>
Expand Down Expand Up @@ -109,6 +117,23 @@ test('.toBeDisabled fieldset>legend', () => {
expect(queryByTestId('outer-fieldset-element')).toBeDisabled()
})

test('.toBeDisabled custom element', () => {
const {queryByTestId} = render(`
<custom-element data-testid="disabled-custom-element" disabled=""></custom-element>
<custom-element data-testid="enabled-custom-element"></custom-element>
`)

expect(queryByTestId('disabled-custom-element')).toBeDisabled()
expect(() => {
expect(queryByTestId('disabled-custom-element')).not.toBeDisabled()
}).toThrowError('element is disabled')

expect(queryByTestId('enabled-custom-element')).not.toBeDisabled()
expect(() => {
expect(queryByTestId('enabled-custom-element')).toBeDisabled()
}).toThrowError('element is not disabled')
})

test('.toBeEnabled', () => {
const {queryByTestId} = render(`
<div>
Expand Down Expand Up @@ -241,3 +266,20 @@ test('.toBeEnabled fieldset>legend', () => {
expect(queryByTestId('outer-fieldset-element')).toBeEnabled()
}).toThrowError()
})

test('.toBeEnabled custom element', () => {
const {queryByTestId} = render(`
<custom-element data-testid="disabled-custom-element" disabled=""></custom-element>
<custom-element data-testid="enabled-custom-element"></custom-element>
`)

expect(queryByTestId('disabled-custom-element')).not.toBeEnabled()
expect(() => {
expect(queryByTestId('disabled-custom-element')).toBeEnabled()
}).toThrowError('element is not enabled')

expect(queryByTestId('enabled-custom-element')).toBeEnabled()
expect(() => {
expect(queryByTestId('enabled-custom-element')).not.toBeEnabled()
}).toThrowError('element is enabled')
})
Loading