CINXE.COM
<!doctype html> <html lang="en" dir="ltr" class="plugin-pages plugin-id-default"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="generator" content="Docusaurus v2.0.1"> <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Testing Library RSS Feed"> <link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Testing Library Atom Feed"> <link rel="alternate" type="application/json" href="/blog/feed.json" title="Testing Library JSON Feed"> <link rel="preconnect" href="https://www.google-analytics.com"> <link rel="preconnect" href="https://www.googletagmanager.com"> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-137787095-1"></script> <script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","UA-137787095-1",{})</script> <link rel="search" type="application/opensearchdescription+xml" title="Testing Library" href="/opensearch.xml"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=IBM+Plex+Mono:500,700|Source+Code+Pro:500,700|Source+Sans+Pro:400,400i,700"> <script src="https://buttons.github.io/buttons.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script><title data-rh="true">Testing Library | Testing Library</title><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://testing-library.com/img/octopus-128x128.png"><meta data-rh="true" name="twitter:image" content="https://testing-library.com/img/octopus-128x128.png"><meta data-rh="true" property="og:url" content="https://testing-library.com/"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docusaurus_tag" content="default"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docsearch:docusaurus_tag" content="default"><meta data-rh="true" property="og:title" content="Testing Library | Testing Library"><meta data-rh="true" name="description" content="Simple and complete testing utilities that encourage good testing practices"><meta data-rh="true" property="og:description" content="Simple and complete testing utilities that encourage good testing practices"><link data-rh="true" rel="icon" href="/img/octopus-32x32.png"><link data-rh="true" rel="canonical" href="https://testing-library.com/"><link data-rh="true" rel="alternate" href="https://testing-library.com/" hreflang="en"><link data-rh="true" rel="alternate" href="https://testing-library.com/" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://TUPO88CFRP-dsn.algolia.net" crossorigin="anonymous"><script data-rh="true">function maybeInsertBanner(){window.__DOCUSAURUS_INSERT_BASEURL_BANNER&&insertBanner()}function insertBanner(){var n=document.getElementById("docusaurus-base-url-issue-banner-container");if(n){n.innerHTML='\n<div id="docusaurus-base-url-issue-banner" style="border: thick solid red; background-color: rgb(255, 230, 179); margin: 20px; padding: 20px; font-size: 20px;">\n <p style="font-weight: bold; font-size: 30px;">Your Docusaurus site did not load properly.</p>\n <p>A very common reason is a wrong site <a href="https://docusaurus.io/docs/docusaurus.config.js/#baseurl" style="font-weight: bold;">baseUrl configuration</a>.</p>\n <p>Current configured baseUrl = <span style="font-weight: bold; color: red;">/</span> (default value)</p>\n <p>We suggest trying baseUrl = <span id="docusaurus-base-url-issue-banner-suggestion-container" style="font-weight: bold; color: green;"></span></p>\n</div>\n';var e=document.getElementById("docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname,r="/"===s.substr(-1)?s:s+"/";e.innerHTML=r}}window.__DOCUSAURUS_INSERT_BASEURL_BANNER=!0,document.addEventListener("DOMContentLoaded",maybeInsertBanner)</script><link rel="stylesheet" href="/assets/css/styles.67d9695e.css"> <link rel="preload" href="/assets/js/runtime~main.4057d163.js" as="script"> <link rel="preload" href="/assets/js/main.b5a7962b.js" as="script"> </head> <body class="navigation-with-keyboard"> <script>!function(){function e(e){document.documentElement.setAttribute("data-theme",e)}var t=function(){var e=null;try{e=localStorage.getItem("theme")}catch(e){}return e}();null!==t?e(t):window.matchMedia("(prefers-color-scheme: dark)").matches?e("dark"):(window.matchMedia("(prefers-color-scheme: light)").matches,e("light"))}()</script><div id="__docusaurus"> <div id="docusaurus-base-url-issue-banner-container"></div><div role="region"><a href="#" class="skipToContent_fXgn">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Navigation bar toggle" class="navbar__toggle clean-btn" type="button" tabindex="0"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/octopus-64x64.png" alt="An octopus representing the DOM Testing Library Logo" class="themedImage_ToTc themedImage--light_HNdA" height="32" width="32"><img src="/img/octopus-64x64.png" alt="An octopus representing the DOM Testing Library Logo" class="themedImage_ToTc themedImage--dark_i4oU" height="32" width="32"></div><b class="navbar__title text--truncate">Testing Library</b></a><a class="navbar__item navbar__link" href="/docs/">Docs</a><a class="navbar__item navbar__link" href="/docs/recipes">Examples</a></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/help">Help</a><a class="navbar__item navbar__link" href="/blog">Blog</a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div class="main-wrapper mainWrapper_z2l0"><div class="homeContainer"><div class="homeSplashFade"><div class="wrapper homeWrapper"><div class="projectLogo"><img src="/img/logo-large.png" alt="Project Logo" height="128" width="128"></div><div class="inner"><div><h2 class="projectTitle">Testing Library</h2><div class="projectTaglineWrapper"><p class="projectTagline">Simple and complete testing utilities that encourage good testing practices</p></div></div><div class="pluginWrapper buttonWrapper"><a class="button button--primary button--outline" href="/docs/">Get Started</a></div></div></div></div></div><div class="mainContainer"><div class="block-container lightBackground paddingBottom paddingTop"><div class="wrapper"><div style="text-align:center"><p><i>The more your tests resemble the way your software is used, <br>the more confidence they can give you.</i></p></div></div></div><div class="block-container paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement alignCenter imageAlignTop twoByGridBlock"><div class="blockImage"><img src="/img/wrench-128x128.png" alt="" width="80" height="80"></div><div class="blockContent"><h2><div><p>Write Maintainable Tests</p> </div></h2><div><p>Tests only break when your app breaks, not implementation details</p> </div></div></div><div class="blockElement alignCenter imageAlignTop twoByGridBlock"><div class="blockImage"><img src="/img/check-128x128.png" alt="" width="80" height="80"></div><div class="blockContent"><h2><div><p>Develop with Confidence</p> </div></h2><div><p>Interact with your app the same way as your users</p> </div></div></div><div class="blockElement alignCenter imageAlignTop twoByGridBlock"><div class="blockImage"><img src="/img/tada-128x128.png" alt="" width="80" height="80"></div><div class="blockContent"><h2><div><p>Accessible by Default</p> </div></h2><div><p>Built-in selectors find elements the way users do to help you write inclusive code</p> </div></div></div></div></div></div><div class="block-container lightBackground paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement imageAlignSide imageAlignLeft twoByGridBlock"><div class="blockImage"><img src="/img/interrobang-128x128.png" alt="The problem (picture of a question mark)" height="128"></div><div class="blockContent"><div><h2>The Problem</h2> <ul> <li>You want tests for your UI that avoid including implementation details and rather focus on making your tests give you the confidence for which they are intended.</li> <li>You want your tests to be maintainable so refactors <em>(changes to implementation but not functionality)</em> don't break your tests and slow you and your team down.</li> </ul> </div></div></div></div></div></div><div class="block-container paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement imageAlignSide imageAlignRight twoByGridBlock"><div class="blockContent"><div><h2>The Solution</h2> <p>The Testing Library family of libraries is a very light-weight solution for testing without all the implementation details. The main utilities it provides involve querying for nodes similarly to how users would find them. In this way, testing-library helps ensure your tests give you confidence in your UI code.</p> </div></div><div class="blockImage"><img src="/img/star-128x128.png" alt="The solution (picture of a star)" height="128"></div></div></div></div></div><div class="block-container lightBackground paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement imageAlignSide imageAlignLeft twoByGridBlock"><div class="blockImage"><img src="/img/trophy-128x128.png" alt="The guiding principle (picture of a brick wall)" height="128"></div><div class="blockContent"><h2><div><p>Guiding Principle</p> </div></h2><div><p><em>The more your tests resemble the way your software is used, the more confidence they can give you.</em></p> </div></div></div></div></div></div><div class="productShowcaseSection paddingBottom paddingTop"><h2>Who is Using This?</h2><div class="logos"><a href="https://www.autodesk.com"><img src="/img/users/autodesk.svg" alt="Autodesk" title="Autodesk"></a><a href="https://www.expediagroup.com"><img src="/img/users/expediagroup.svg" alt="Expedia Group" title="Expedia Group"></a><a href="https://opensource.facebook.com"><img src="/img/users/facebook-open-source.png" alt="Facebook Open Source" title="Facebook Open Source"></a><a href="https://www.paypal.com"><img src="/img/users/paypal.svg" alt="PayPal" title="PayPal"></a><a href="https://www.walmartlabs.com/"><img src="/img/users/walmart.png" alt="Walmart Labs" title="Walmart Labs"></a></div><a class="button button--primary button--outline" href="/users">More <!-- -->Testing Library<!-- --> Users</a></div><div class="block-container paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/react-128x128.png" alt="React logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/react-testing-library/intro">React</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/vue-400x400.png" alt="Vue logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/vue-testing-library/intro">Vue</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/angular-128x128.png" alt="Angular logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/angular-testing-library/intro">Angular</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/svelte-logo.png" alt="Svelte logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/svelte-testing-library/intro">Svelte</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/preact-128x128.png" alt="Preact logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/preact-testing-library/intro">Preact</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/reason-200x200.png" alt="ReasonReact logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/bs-react-testing-library/intro">ReasonReact</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/react-native-128x128.png" alt="React Native logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/react-native-testing-library/intro">React Native</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/cypress-128x128.png" alt="Cypress logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/cypress-testing-library/intro">Cypress</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/puppeteer-275x275.png" alt="Puppeteer logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/pptr-testing-library/intro">Puppeteer</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/testcafe-128x128.jpg" alt="Testcafe logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/testcafe-testing-library/intro">Testcafe</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/nightwatch-128x128.png" alt="Nightwatch logo" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/nightwatch-testing-library/intro">Nightwatch</a></p> </div></h2><div></div></div></div><div class="blockElement alignCenter fourByGridBlock imageAlignTop"><div class="blockImage"><img src="/img/construction-128x128.png" alt="" height="80"></div><div class="blockContent"><h2><div><p><a href="./docs/user-event/intro">And more...</a></p> </div></h2><div></div></div></div></div></div></div><div class="awardsSection paddingBottom paddingTop"><h2>Awards</h2><div class="block-container paddingBottom paddingTop"><div class="wrapper"><div class="gridBlock"><div class="blockElement alignCenter imageAlignTop threeByGridBlock"><div class="blockImage"><a href="https://osawards.com/react/2019"><img src="/img/impactful-contribution-award-399x544.png" alt="Winner of the Open Source Awards 2019 in the category "The most impactful contribution to the community"" height="273"></a></div><div class="blockContent"><div></div></div></div><div class="blockElement alignCenter imageAlignTop threeByGridBlock"><div class="blockImage"><a href="https://2020.stateofjs.com/en-US/awards/"><img src="/img/highest-satisfaction-638x574.png" alt="Winner of the State of JS 2020 award for the technology with the highest percentage of satisfied users" height="180"></a></div><div class="blockContent"><div></div></div></div></div></div></div></div></div></div><footer class="footer"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Docs</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/docs">Getting Started</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/example-codesandbox">Examples</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/dom-testing-library/api">API</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/dom-testing-library/faq">Help</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/blog">Blog</a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/react-testing-library" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://discord.gg/testing-library" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"> <a target="_blank" rel="noreferrer noopener" class="github-button" href="https://github.com/testing-library/react-testing-library" data-icon="octicon-star" data-count-href="/testing-library/react-testing-library/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a> </li><li class="footer__item"><a href="https://github.com/testing-library" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://github.com/testing-library/testing-library-docs" target="_blank" rel="noopener noreferrer" class="footer__link-item">Edit Docs on GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://netlify.com" target="_blank" rel="noopener noreferrer" class="footer__link-item">Hosted by Netlify<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><img src="/img/octopus-128x128.png" alt="An octopus representing the DOM Testing Library Logo" class="themedImage_ToTc themedImage--light_HNdA footer__logo" width="128" height="128"><img src="/img/octopus-128x128.png" alt="An octopus representing the DOM Testing Library Logo" class="themedImage_ToTc themedImage--dark_i4oU footer__logo" width="128" height="128"></div><div class="footer__copyright">Copyright 漏 2018-2024 Kent C. Dodds and contributors</div></div></div></footer></div> <script src="/assets/js/runtime~main.4057d163.js"></script> <script src="/assets/js/main.b5a7962b.js"></script> </body> </html>