Files
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

1.4 KiB

Testing

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

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