Saltar al contenido

Pruebas

Write tests to prevent regressions and write better code.

Userspace

It's generally recommended to test your application without tying the tests too closely to Material-UI. This is how Material-UI components are tested internally. A library that has a first-class API for this approach is @testing-library/react.

For example, when rendering a TextField your test should not need to query for the specific Material-UI instance of the TextField but rather for the input, or [role="textbox"].

By not relying on the React component tree you make your test more robust against internal changes in Material-UI or, if you need snapshot testing, adding additional wrapper components such as context providers. We don't recommend snapshot testing though. "Effective snapshot testing" by Kent C. Dodds goes into more details why snapshot testing might be misleading for React component tests.

Internal

Material-UI has a wide range of tests so we can iterate with confidence on the components, for instance, the visual regression tests provided by Argos-CI have proven to be really helpful. To learn more about the internal tests, you can have a look at the README.