Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active August 3, 2019 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcdodds/9ba7142db63537cabfe2729268f532d1 to your computer and use it in GitHub Desktop.
Save kentcdodds/9ba7142db63537cabfe2729268f532d1 to your computer and use it in GitHub Desktop.
example jest output for failed role assertion
FAIL src/screens/__tests__/book.js
✕ renders all the book information (173ms)
● renders all the book information
Unable to find an element with the role "blah"
Here are the available roles:
img:
<img
alt="ullam quis consectetur book cover"
class="css-1dlbu0h-BookScreen"
src="http://lorempixel.com/640/480"
/>
--------------------------------------------------
heading:
<h1 />
--------------------------------------------------
button:
<button
class="css-lofz2f-TooltipButton"
/>
--------------------------------------------------
<body>
<div>
<div>
<div
class="css-1mltn4g-BookScreen"
>
<img
alt="ullam quis consectetur book cover"
class="css-1dlbu0h-BookScreen"
src="http://lorempixel.com/640/480"
/>
<div>
<div
class="css-1sigr6f-BookScreen"
>
<div
class="css-139h67i-BookScreen"
>
<h1>
ullam quis consectetur
</h1>
<div>
<i>
Marina Ortiz
</i>
<span
class="css-1em651t-BookScreen"
>
|
</span>
<i>
Tremblay, Jenkins and Turcotte
</i>
</div>
</div>
<div
class="css-1e3akjp-BookScreen"
>
<div
aria-label="Add to list"
>
<button
class="css-lofz2f-TooltipButton"
>
<svg
fill="currentColor"
height="1em"
stroke="currentColor"
stroke-width="0"
viewBox="0 0 512 512"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"
/>
</svg>
</button>
</div>
</div>
</div>
<div
class="css-1pfti2p-BookScreen"
/>
<br />
<p>
Corporis et sit illum autem. Corrupti sint molestiae deserunt voluptas cum possimus quia. Qui quos voluptatum dicta. Rem fugit natus soluta.
</p>
</div>
</div>
</div>
</div>
</body>
66 | } = await renderBookScreen({listItem: null})
67 |
> 68 | getByRole('blah')
| ^
69 |
70 | getByText(book.title)
71 | getByText(book.author)
at getElementError (node_modules/@testing-library/dom/dist/query-helpers.js:46:10)
at node_modules/@testing-library/dom/dist/query-helpers.js:100:13
at node_modules/@testing-library/dom/dist/query-helpers.js:83:17
at Object.getByRole (src/screens/__tests__/book.js:68:3)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.027s
Ran all test suites matching /src\/screens\/__tests__\/book.js/i.
Watch Usage: Press w to show more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment