Try our Chrome extension
Easily add the current web-page from your browser directly into your changedetection.io tool, more great features coming soon!Changedetection.io needs your support!
You can help us by supporting changedetection.io on these platforms;
- Rate us at AlternativeTo.net
- Star us on GitHub
- Follow us at Twitter/X
- G2 Software reviews
- Check us out on LinkedIn
- And tell your friends and colleagues :)
The more popular changedetection.io is, the more time we can dedicate to adding amazing features!
Many thanks :)
changedetection.io team
Aรบn no hace unos segundos
False
Aรบn no hace unos segundos
Texto activado Texto ignorado Texto bloqueado
hace 6 horas
Skip to content
Navigation Menu
Sign in Appearance settings
* Platform
+ AI CODE CREATION
o GitHub Copilot Write better code with AI
o GitHub Copilot app Direct agents from issue to merge
o MCP Registry Integrate external tools
+ DEVELOPER WORKFLOWS
o Actions Automate any workflow
o Codespaces Instant dev environments
o Issues Plan and track work
o Code Review Manage code changes
o Code Quality Enforce quality at merge
+ APPLICATION SECURITY
o GitHub Advanced Security Find and fix vulnerabilities
o Code security Secure your code as you build
o Secret protection Stop leaks before they start
+ EXPLORE
o Why GitHub
o Documentation
o Blog
o Changelog
o Marketplace
View all features
* Solutions
+ BY COMPANY SIZE
o Enterprises
o Small and medium teams
o Startups
o Nonprofits
+ BY USE CASE
o App Modernization
o DevSecOps
o DevOps
o CI/CD
o View all use cases
+ BY INDUSTRY
o Healthcare
o Financial services
o Manufacturing
o Government
o View all industries
View all solutions
* Resources
+ EXPLORE BY TOPIC
o AI
o Software Development
o DevOps
o Security
o View all topics
+ EXPLORE BY TYPE
o Customer stories
o Events & webinars
o Ebooks & reports
o Business insights
o GitHub Skills
+ SUPPORT & SERVICES
o Documentation
o Customer support
o Community forum
o Trust center
o Partners
View all resources
* Open Source
+ COMMUNITY
o GitHub Sponsors Fund open source developers
+ PROGRAMS
o Security Lab
o Maintainer Community
o Accelerator
o GitHub Stars
o Archive Program
+ REPOSITORIES
o Topics
o Trending
o Collections
* Enterprise
+ ENTERPRISE SOLUTIONS
o Enterprise platform AI-powered developer platform
+ AVAILABLE ADD-ONS
o GitHub Advanced Security Enterprise-grade security features
o Copilot for Business Enterprise-grade AI features
o Premium Support Enterprise-grade 24/7 support
* Pricing
Type / to search
Sign in
Sign up Appearance settings
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
Uh oh!
There was an error while loading. Please reload this page.
testing-library / react-testing-library Public
* Notifications You must be signed in to change notification settings
* Fork 1.2k
* Star 19.6k
* Code
* Issues 64
* Pull requests 18
* Actions
* Security and quality 0
* Insights
Additional navigation options
* Code
* Issues
* Pull requests
* Actions
* Security and quality
* Insights
main
Branches Tags
Go to file
Code
Open more actions menu
Folders and files
Name Name Last commit message Last commit date
Latest commit
History
543 Commits
543 Commits
.codesandbox .codesandbox
.github .github
other other
src src
tests tests
types types
.all-contributorsrc .all-contributorsrc
.bundle.main.env .bundle.main.env
.bundle.pure.env .bundle.pure.env
.gitattributes .gitattributes
.gitignore .gitignore
.huskyrc.js .huskyrc.js
.npmrc .npmrc
.prettierignore .prettierignore
.prettierrc.js .prettierrc.js
CHANGELOG.md CHANGELOG.md
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md
CONTRIBUTING.md CONTRIBUTING.md
LICENSE LICENSE
README.md README.md
codecov.yml codecov.yml
dont-cleanup-after-each.js dont-cleanup-after-each.js
jest.config.js jest.config.js
package.json package.json
pure.d.ts pure.d.ts
pure.js pure.js
tsconfig.json tsconfig.json
View all files
Repository files navigation
*
* README
* Code of conduct
* Contributing
* MIT license
More items
React Testing Library
Simple and complete React DOM testing utilities that encourage good testing practices.
Read The Docs | Edit the docs
Table of Contents
* The problem
* The solution
* Installation
+ Suppressing unnecessary warnings on React DOM 16.8
* Examples
+ Basic Example
+ Complex Example
+ More Examples
* Hooks
* Guiding Principles
* Docs
* Issues
+ ๐ Bugs
+ ๐ก Feature Requests
+ โ Questions
* Contributors
* LICENSE
The problem
You want to write maintainable tests for your React components. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
The solution
The React Testing Library is a very lightweight solution for testing React components. It provides light utility functions on top of react-dom and react-dom/test-utils, in a way that encourages better testing practices. Its primary guiding principle is:
The more your tests resemble the way your software is used, the more confidence they can give you.
Installation
This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies.
Starting from RTL version 16, you'll also need to install @testing-library/dom:
npm install --save-dev @testing-library/react @testing-library/dom
or
for installation via yarn
yarn add --dev @testing-library/react @testing-library/dom
This library has peerDependencies listings for react, react-dom and starting from RTL version 16 also @testing-library/dom.
React Testing Library versions 13+ require React v18. If your project uses an older version of React, be sure to install version 12:
npm install --save-dev @testing-library/react@12 yarn add --dev @testing-library/react@12
You may also be interested in installing @testing-library/jest-dom so you can use the custom jest matchers.
Docs
Suppressing unnecessary warnings on React DOM 16.8
There is a known compatibility issue with React DOM 16.8 where you will see the following warning:
Warning: An update to ComponentName inside a test was not wrapped in act(...).
If you cannot upgrade to React DOM 16.9, you may suppress the warnings by adding the following snippet to your test configuration (learn more):
// this is just a little hack to silence a warning that we'll get until we
// upgrade to 16.9. See also: https://github.com/facebook/react/pull/14853
const originalError = console.error
beforeAll(() => {
console.error = (...args) => {
if ( / W a r n i n g . * n o t w r a p p e d i n a c t / .test(args[0])) {
return
}
originalError.call(console, ...args)
}
})
afterAll(() => {
console.error = originalError
})
Examples
Basic Example
// hidden-message.js
import * as React from 'react'
// NOTE: React Testing Library works well with React Hooks and classes.
// Your tests will be the same regardless of how you write your components.
function HiddenMessage({children}) {
const [showMessage, setShowMessage] = React.useState(false)
return (
<div>
<label htmlFor="toggle">Show Message</label>
<input
id="toggle"
type="checkbox"
onChange={e => setShowMessage(e.target.checked)}
checked={showMessage}
/>
{showMessage ? children : null}
</div>
)
}
export default HiddenMessage
// __tests__/hidden-message.js
// these imports are something you'd normally configure Jest to import for you
// automatically. Learn more in the setup docs: https://testing-library.com/docs/react-testing-library/setup#cleanup
import '@testing-library/jest-dom'
// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
import * as React from 'react'
import {render, fireEvent, screen} from '@testing-library/react'
import HiddenMessage from '../hidden-message'
test('shows the children when the checkbox is checked', () => {
const testMessage = 'Test Message'
render(<HiddenMessage>{testMessage}</HiddenMessage>)
// query* functions will return the element or null if it cannot be found
// get* functions will return the element or throw an error if it cannot be found
expect(screen.queryByText(testMessage)).toBeNull()
// the queries can accept a regex to make your selectors more resilient to content tweaks and changes.
fireEvent.click(screen.getByLabelText( / s h o w / i))
// .toBeInTheDocument() is an assertion that comes from jest-dom
// otherwise you could use .toBeDefined()
expect(screen.getByText(testMessage)).toBeInTheDocument()
})
Complex Example
// login.js
import * as React from 'react'
function Login() {
const [state, setState] = React.useReducer((s, a) => ({...s, ...a}), {
resolved: false,
loading: false,
error: null,
})
function handleSubmit(event) {
event.preventDefault()
const {usernameInput, passwordInput} = event.target.elements
setState({loading: true, resolved: false, error: null})
window
.fetch('/api/login', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
username: usernameInput.value,
password: passwordInput.value,
}),
})
.then(r => r.json().then(data => (r.ok ? data : Promise.reject(data))))
.then(
user => {
setState({loading: false, resolved: true, error: null})
window.localStorage.setItem('token', user.token)
},
error => {
setState({loading: false, resolved: false, error: error.message})
},
)
}
return (
<div>
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="usernameInput">Username</label>
<input id="usernameInput" />
</div>
<div>
<label htmlFor="passwordInput">Password</label>
<input id="passwordInput" type="password" />
</div>
<button type="submit">Submit{state.loading ? '...' : null}</button>
</form>
{state.error ? <div role="alert">{state.error}</div> : null}
{state.resolved ? (
<div role="alert">Congrats! You're signed in!</div>
) : null}
</div>
)
}
export default Login
// __tests__/login.js
// again, these first two imports are something you'd normally handle in
// your testing framework configuration rather than importing them in every file.
import '@testing-library/jest-dom'
import * as React from 'react'
// import API mocking utilities from Mock Service Worker.
import {rest} from 'msw'
import {setupServer} from 'msw/node'
// import testing utilities
import {render, fireEvent, screen} from '@testing-library/react'
import Login from '../login'
const fakeUserResponse = {token: 'fake_user_token'}
const server = setupServer(
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.json(fakeUserResponse))
}),
)
beforeAll(() => server.listen())
afterEach(() => {
server.resetHandlers()
window.localStorage.removeItem('token')
})
afterAll(() => server.close())
test('allows the user to login successfully', async () => {
render(<Login />)
// fill out the form
fireEvent.change(screen.getByLabelText( / u s e r n a m e / i), {
target: {value: 'chuck'},
})
fireEvent.change(screen.getByLabelText( / p a s s w o r d / i), {
target: {value: 'norris'},
})
fireEvent.click(screen.getByText( / s u b m i t / i))
// just like a manual tester, we'll instruct our test to wait for the alert
// to show up before continuing with our assertions.
const alert = await screen.findByRole('alert')
// .toHaveTextContent() comes from jest-dom's assertions
// otherwise you could use expect(alert.textContent).toMatch(/congrats/i)
// but jest-dom will give you better error messages which is why it's recommended
expect(alert).toHaveTextContent( / c o n g r a t s / i)
expect(window.localStorage.getItem('token')).toEqual(fakeUserResponse.token)
})
test('handles server exceptions', async () => {
// mock the server error response for this test suite only.
server.use(
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.status(500), ctx.json({message: 'Internal server error'}))
}),
)
render(<Login />)
// fill out the form
fireEvent.change(screen.getByLabelText( / u s e r n a m e / i), {
target: {value: 'chuck'},
})
fireEvent.change(screen.getByLabelText( / p a s s w o r d / i), {
target: {value: 'norris'},
})
fireEvent.click(screen.getByText( / s u b m i t / i))
// wait for the error message
const alert = await screen.findByRole('alert')
expect(alert).toHaveTextContent( / i n t e r n a l s e r v e r e r r o r / i)
expect(window.localStorage.getItem('token')).toBeNull()
})
We recommend using Mock Service Worker library to declaratively mock API communication in your tests instead of stubbing window.fetch, or relying on third-party adapters.
More Examples
We're in the process of moving examples to the docs site
You'll find runnable examples of testing with different libraries in the react-testing-library-examples codesandbox. Some included are:
* react-redux
* react-router
* react-context
Hooks
If you are interested in testing a custom hook, check out React Hooks Testing Library.
NOTE: it is not recommended to test single-use custom hooks in isolation from the components where it's being used. It's better to test the component that's using the hook rather than the hook itself. The React Hooks Testing Library is intended to be used for reusable hooks/libraries.
Guiding Principles
The more your tests resemble the way your software is used, the more confidence they can give you.
We try to only expose methods and utilities that encourage you to write tests that closely resemble how your React components are used.
Utilities are included in this project based on the following guiding principles:
1. If it relates to rendering components, it deals with DOM nodes rather than component instances, nor should it encourage dealing with component instances.
2. It should be generally useful for testing individual React components or full React applications. While this library is focused on react-dom, utilities could be included even if they don't directly relate to react-dom.
3. Utility implementations and APIs should be simple and flexible.
Most importantly, we want React Testing Library to be pretty light-weight, simple, and easy to understand.
Docs
Read The Docs | Edit the docs
Issues
Looking to contribute? Look for the Good First Issue label.
๐ Bugs
Please file an issue for bugs, missing documentation, or unexpected behavior.
See Bugs
๐ก Feature Requests
Please file an issue to suggest new features. Vote on feature requests by adding a ๐. This helps maintainers prioritize what to work on.
See Feature Requests
โ Questions
For questions related to using the library, please visit a support community instead of filing an issue on GitHub.
* Discord
* Stack Overflow
Contributors
Thanks goes to these people (emoji key):
Kent C. Dodds Ryan Castner Daniel Sandiego Paweล Mikoลajczyk Alejandro รรกรฑez Ortiz Matt Parrish Justin Hall
๐ป ๐ ๐ โ ๏ธ ๐ ๐ป ๐ป ๐ ๐ ๐ป ๐ โ ๏ธ ๐ฆ
Anto Aravinth Jonah Moses ลukasz Gandecki Ivan Babak Jesse Day Ernesto Garcรญa Josef Maxx Blake
๐ป โ ๏ธ ๐ ๐ ๐ป โ ๏ธ ๐ ๐ ๐ค ๐ป ๐ฌ ๐ป ๐ ๐ป ๐ โ ๏ธ
Michal Baranowski Arthur Puthin Thomas Chia Thiago Galvani Christian Alex Krolick Johann Hubert Sonntagbauer
๐ โ
๐ ๐ป ๐ ๐ โ ๏ธ ๐ฌ ๐ ๐ก ๐ค ๐ป ๐ โ ๏ธ
Maddi Joyce Ryan Vice Ian Wilson Daniel Giorgio Polvara John Gozde Sam Horton
๐ป ๐ ๐ โ
๐ ๐ป ๐ ๐ค ๐ป ๐ ๐ก ๐ค
Richard Kotze (mobile) Brahian E. Soto Mercedes Benoit de La Forest Salah Adam Gordon Matija Marohniฤ Justice Mba
๐ ๐ ๐ ๐ป โ ๏ธ ๐ ๐ป ๐ ๐
Mark Pollmann Ehtesham Kafeel Julio Pavรณn Duncan L Tiago Almeida Robert Smith Zach Green
๐ ๐ป ๐ ๐ป ๐ ๐ก ๐ ๐ ๐
dadamssg Yazan Aabed Tim Divyanshu Maithani Deepak Grover Eyal Cohen Peter Makowski
๐ ๐ ๐ ๐ป ๐ โ ๏ธ โ
๐น โ
๐น ๐ ๐
Michiel Nuyts Joe Ng'ethe Kate Sean James Long Herb Hagely Alex Wendte
๐ ๐ป ๐ ๐ ๐ ๐ค ๐ฆ ๐ก ๐ก
Monica Powell Vitaly Sivkov Weyert de Boer EstebanMarin Victor Martins Royston Shufflebotham chrbala
๐ ๐ป ๐ค ๐ ๐จ ๐ ๐ ๐ ๐ ๐ก ๐ป
Donavon West Richard Maisano Marco Biedermann Alex Zherdev Andrรฉ Matulionis dos Santos Daniel K. mohamedmagdy17593
๐ป ๐ ๐ค โ ๏ธ ๐ป ๐ป ๐ง โ ๏ธ ๐ ๐ป ๐ป ๐ก โ ๏ธ ๐ ๐ป ๐ค โ ๏ธ ๐ ๐ป
Loren โบ๏ธ MarkFalconbridge Vinicius Peter Schyma Ian Schmitz Joel Marcotte Alejandro Dustet
๐ ๐ ๐ป ๐ ๐ก ๐ป ๐ ๐ โ ๏ธ ๐ป ๐
Brandon Carroll Lucas Machado Pascal Duez Minh Nguyen LiaoJimmy Sunil Pai Dan Abramov
๐ ๐ ๐ฆ ๐ป ๐ ๐ป โ ๏ธ ๐
Christian Murphy Ivakhnenko Dmitry James George Joรฃo Fernandes Alejandro Perea Nick McCurdy Sebastian Silbermann
๐ ๐ป ๐ ๐ ๐ ๐ ๐ฌ ๐ ๐
Adriร Fontcuberta John Reilly Michaรซl De Boey Tim Yates Brian Donovan Noam Gabriel Jacobson Ronald van der Kooij
๐ ๐ ๐ ๐ ๐ป ๐ ๐ป ๐ โ ๏ธ ๐ป
Aayush Rajvanshi Ely Alamillo Daniel Afonso Laurens Bosscher Sakito Mukai Tรผrker Teke Zach Brogan
๐ ๐ป โ ๏ธ ๐ป โ ๏ธ ๐ป ๐ ๐ ๐ป โ ๏ธ
Ryota Murakami Michael Hottman Steven Fitzpatrick Juan Je Garcรญa Championrunner Sam Tsai Christian Rackerseder
๐ ๐ค ๐ ๐ ๐ ๐ป โ ๏ธ ๐ ๐ป
Andrei Picus Artem Zakharchenko Michael Braden Lee Kamran Ayub Matan Borenkraout Ryan Bigg
๐ ๐ ๐ ๐ ๐ ๐ป โ ๏ธ ๐ป ๐ง
Anton Halim Artem Malko Gerrit Alex Karthick Raja Abdelrahman Ashraf Lidor Avitan Jordan Harband
๐ ๐ป ๐ป ๐ป ๐ป ๐ ๐ ๐ค
Marco Moretti sanchit121 Solufa Ari Perkkiรถ Johannes Ewald Angus J. Pope Dominik Lesch
๐ป ๐ ๐ป ๐ ๐ป โ ๏ธ ๐ป ๐ ๐
Marcos Gรณmez Akash Shyam Fabian Meumertzheim Sebastian Malton Martin Bรถttcher Dominik Dorfmeister Stephen Sauceda
๐ ๐ ๐ป ๐ ๐ ๐ป ๐ป ๐ป ๐
Colin Diesh Yusuke Iinuma Jeff Way Bernardo Belchior
๐ ๐ป ๐ป ๐ป ๐
This project follows the all-contributors specification. Contributions of any kind welcome!
LICENSE
MIT
About
๐ Simple and complete React DOM testing utilities that encourage good testing practices.
testing-library.com/react
Topics
javascriptreactjstesting
Resources
Readme
MIT license
Code of conduct
Code of conduct
Contributing
Contributing
Activity
Custom properties
Stars
19.6k stars
Watchers
139 watching
Forks
1.2k forks
Report repository
Releases
Used by
Contributors
Languages
Footer
ยฉ 2026 GitHub, Inc.
Footer navigation
* Terms
* Privacy
* Security
* Status
* Community
* Docs
* Contact
* Manage cookies
* Do not share my personal information
You canโt perform that action at this time.
Por ahora, las diferencias se realizan en texto, no grรกficamente, solo estรก disponible la รบltima captura de pantalla.
La captura de pantalla requiere un buscador de contenido (Sockpuppetbrowser, selenium, etc.) que admita capturas de pantalla.