top of page
Logo der Online Agentur mdwp

Enzyme

Enzyme is a JavaScript utility library for testing React components. It's developed by Airbnb and is a commonly used testing tool in the React ecosystem. Enzyme makes it easier to manipulate, traverse, and interact with the render outputs of our components in our tests. It allows us to easily find and interact with elements, simulate events, and make assertions about how the component behaves.

One of the biggest benefits offered by Enzyme is its shallow rendering capability. Shallow rendering is an approach used for testing React components where the functionality of a component is tested without any concern for its child components. This means when a component is rendered, only the output of the component itself is considered and not any of its child component’s output.

Here is an example of a unit test developed using Enzyme:

```javascript
import { shallow } from 'enzyme';
import App from './App';

describe('<App />', () => {
it('renders without crashing', () => {
shallow(<App />);
});
});
```

In this case, the `shallow()` function is used to render the <App> component for testing. The test checks if the component can be rendered without any errors. If the component is rendered without errors, the test will pass.

Remember, to use Enzyme, you need to install it by running `$ npm i --save enzyme` in your command line or terminal.

bottom of page