It could be useful in situations where the code being tested renders html that Why testing against a specific DOM structure is not advised. We encourage testingįrom the perspective of how the user perceives the app in a browser. toContainHTML ( '' )Ĭhances are you probably do not need to use this matcher. toContainHTML ( 'data-testid' ) expect ( getByTestId ( 'parent' ) ). toContainHTML ( 'data-testid="child"' ) expect ( getByTestId ( 'parent' ) ). toContainHTML ( '' ) // These won't work expect ( getByTestId ( 'parent' ) ). toContainHTML ( '' ) expect ( getByTestId ( 'parent' ) ). These are valid uses expect ( getByTestId ( 'parent' ) ). Import once (for instance in your tests setup Readability by ensuring you are using the right matchers in your tests. yarn add -dev We also recommend installing the jest-dom eslint plugin which providesĪuto-fixable lint rules that prevent false positive tests and improve test Should be installed as one of your project's devDependencies: npm install -save-dev installation with yarn package manager. This module is distributed via npm which is bundled with node and These will make your tests more declarative,Ĭlear to read and to maintain. The library provides a set of custom jest matchers Checking for an element's attributes, its textĬontent, its css classes, you name it. As part of that goal, you want to avoid all the repetitive You want to use jest to write tests that assert various things about the Custom jest matchers to test the state of the DOM
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |