Skip to content

Getroles logroles #285

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
merged 34 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b6ce430
Added npm package lodash.merge
michaellasky Jun 14, 2019
c5abc46
Add `getRoles` and `logRoles` utilities #282
michaellasky Jun 14, 2019
eea0dfe
Updated logRole test to not rely on snapshot
michaellasky Jun 14, 2019
608681d
Added role-helpers export to index.js
michaellasky Jun 14, 2019
8c4ca7c
Changed formatting of logRoles
michaellasky Jun 15, 2019
cf3c1c5
Removed some tests that weren't needed
michaellasky Jun 15, 2019
b179086
Refactored getRoles and updated related tests
michaellasky Jun 15, 2019
556857f
Removed export of buildElementRoleList
michaellasky Jun 15, 2019
aaf0254
Removed lodash.merge dependency
michaellasky Jun 15, 2019
f362406
Minor: removed a useless -1
michaellasky Jun 15, 2019
cb21991
Minor: statement no longer had to be temp literal
michaellasky Jun 15, 2019
ee95972
Reasability / sanity pass
michaellasky Jun 15, 2019
fbd7e2b
Initial value for reducer switched to array
michaellasky Jun 15, 2019
22dbce9
Fixed bug with node selectors on specificity > 0 nodes
michaellasky Jun 15, 2019
2814797
Added the role-helpers snapshot
michaellasky Jun 15, 2019
7b5ecb1
Added basic test coverage for getImplicitAriaRole
michaellasky Jun 15, 2019
e96cbbd
Removed un-needed branch
michaellasky Jun 15, 2019
afd42c0
Minor: Added a cleanup afterEach test
michaellasky Jun 15, 2019
76c2d3f
Removed unneeded elementRoleMap
michaellasky Jun 15, 2019
a5a81c8
getRoles now handles muultiple implicit roles
michaellasky Jun 17, 2019
6ad8ef9
Added npm package jest-serializer-ansi
michaellasky Jun 18, 2019
02ab1b9
Snapshot now uses jest-serilizer-ansi
michaellasky Jun 18, 2019
e452465
Tests now use jest-serilizer-ansi
michaellasky Jun 18, 2019
de5bf5c
Switched '#' to '-' in the output of logRoles
michaellasky Jun 18, 2019
2ecda86
role-helpers test minor change to reduce LOC
michaellasky Jun 18, 2019
0a87a5d
Removed elementRoleList from role-helpers export
michaellasky Jun 18, 2019
b9a16e1
Made public-api exports from role-helpers spcific
michaellasky Jun 18, 2019
3c5b545
Minor: made testids more consistent
michaellasky Jun 18, 2019
f148198
Minor: '\n' handling is more consistent in logRoles
michaellasky Jun 18, 2019
5cce4cc
Merge branch 'master' into getroles-logroles
michaellasky Jun 19, 2019
93f9530
Added TS definitions for getRoles, logRoles
michaellasky Jun 23, 2019
f1421ce
Merge branch 'master' of https://github.com/testing-library/dom-testi…
michaellasky Jun 23, 2019
593c33f
Changed logRoles formatting
michaellasky Jun 24, 2019
f95b293
Fixed spelling error
michaellasky Jun 24, 2019
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dtslint": "^0.7.7",
"jest-dom": "^3.4.0",
"jest-in-case": "^1.0.2",
"jest-serializer-ansi": "^1.0.3",
"jest-watch-select-projects": "^0.1.1",
"jsdom": "^15.1.1",
"kcd-scripts": "^1.4.0"
Expand Down
163 changes: 163 additions & 0 deletions src/__tests__/__snapshots__/role-helpers.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`logRoles logs expected roles for various dom nodes 1`] = `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks really good. Would love to hear what others have to say though.

"region ------------------------------------

<section
data-testid="a-section"
/>


navigation --------------------------------

<nav
data-testid="a-nav"
/>


heading -----------------------------------

<h1
data-testid="a-h1"
/>

<h2
data-testid="a-h2"
/>

<h3
data-testid="a-h3"
/>


article -----------------------------------

<article
data-testid="a-article"
/>


command -----------------------------------

<menuitem
data-testid="a-menuitem-1"
/>

<menuitem
data-testid="a-menuitem-2"
/>


menuitem ----------------------------------

<menuitem
data-testid="a-menuitem-1"
/>

<menuitem
data-testid="a-menuitem-2"
/>


list --------------------------------------

<ul
data-testid="a-list"
/>

<ul
data-testid="b-list"
/>


listitem ----------------------------------

<li
data-testid="a-list-item-1"
/>

<li
data-testid="a-list-item-2"
/>

<li
data-testid="b-list-item-1"
/>

<li
data-testid="b-list-item-2"
/>


table -------------------------------------

<table
data-testid="a-table"
/>


rowgroup ----------------------------------

<tbody
data-testid="a-tbody"
/>


row ---------------------------------------

<tr
data-testid="a-row"
/>


cell --------------------------------------

<td
data-testid="a-cell-1"
/>

<td
data-testid="a-cell-2"
/>

<td
data-testid="a-cell-3"
/>


form --------------------------------------

<form
data-testid="a-form"
/>


radio -------------------------------------

<input
data-testid="a-radio-1"
type="radio"
/>

<input
data-testid="a-radio-2"
type="radio"
/>


textbox -----------------------------------

<input
data-testid="a-input-1"
type="text"
/>

<input
data-testid="a-input-2"
type="text"
/>

<textarea
data-testid="a-textarea"
/>"
`;
72 changes: 37 additions & 35 deletions src/__tests__/element-queries.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import jestSerializerAnsi from 'jest-serializer-ansi'
import {configure} from '../config'
import {render, renderIntoDocument} from './helpers/test-utils'

expect.addSnapshotSerializer(jestSerializerAnsi)
beforeEach(() => {
document.defaultView.Cypress = null
})
Expand Down Expand Up @@ -37,60 +39,60 @@ test('get throws a useful error message', () => {
.toThrowErrorMatchingInlineSnapshot(`
"Unable to find a label with the text of: LucyRicardo

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByPlaceholderText('LucyRicardo'))
.toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the placeholder text of: LucyRicardo

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the text: LucyRicardo. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByTestId('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element by: [data-testid=\\"LucyRicardo\\"]
"Unable to find an element by: [data-testid="LucyRicardo"]

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByAltText('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the alt text: LucyRicardo

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByTitle('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the title: LucyRicardo.

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByDisplayValue('LucyRicardo'))
.toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element with the value: LucyRicardo.

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
expect(() => getByRole('LucyRicardo')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an element by [role=LucyRicardo]

<div>
<div />
</div>"
<div>
<div />
</div>"
`)
})

Expand Down Expand Up @@ -221,25 +223,25 @@ test('label with no form control', () => {
const {getByLabelText, queryByLabelText} = render(`<label>All alone</label>`)
expect(queryByLabelText(/alone/)).toBeNull()
expect(() => getByLabelText(/alone/)).toThrowErrorMatchingInlineSnapshot(`
"Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the \\"for\\" attribute or \\"aria-labelledby\\" attribute correctly.
"Found a label with the text of: /alone/, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.

<div>
<label>
All alone
</label>
</div>"
<div>
<label>
All alone
</label>
</div>"
`)
})

test('totally empty label', () => {
const {getByLabelText, queryByLabelText} = render(`<label />`)
expect(queryByLabelText('')).toBeNull()
expect(() => getByLabelText('')).toThrowErrorMatchingInlineSnapshot(`
"Found a label with the text of: , however no form control was found associated to that label. Make sure you're using the \\"for\\" attribute or \\"aria-labelledby\\" attribute correctly.
"Found a label with the text of: , however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.

<div>
<label />
</div>"
<div>
<label />
</div>"
`)
})

Expand Down
21 changes: 12 additions & 9 deletions src/__tests__/pretty-dom.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import jestSerializerAnsi from 'jest-serializer-ansi'
import {prettyDOM} from '../pretty-dom'
import {render} from './helpers/test-utils'

expect.addSnapshotSerializer(jestSerializerAnsi)

test('it prints out the given DOM element tree', () => {
const {container} = render('<div>Hello World!</div>')
expect(prettyDOM(container)).toMatchInlineSnapshot(`
"<div>
<div>
Hello World!
</div>
</div>"
"<div>
<div>
Hello World!
</div>
</div>"
`)
})

Expand All @@ -19,9 +22,9 @@ test('it supports truncating the output length', () => {

test('it supports receiving the document element', () => {
expect(prettyDOM(document)).toMatchInlineSnapshot(`
"<html>
<head />
<body />
</html>"
"<html>
<head />
<body />
</html>"
`)
})
Loading