top of page
Logo der Online Agentur mdwp

Jest

Jest is a JavaScript testing framework developed by Facebook, which is widely used for testing React JS applications. It's known for its simplicity and flexibility, as well as its ability to run tests in parallel, offering a better performance than many other testing frameworks.

Jest is also "zero-configuration", meaning jest does not necessarily need any configuration to run tests, which makes it a go-to test runner for many types of JavaScript applications beyond just React.

It provides features such as a simple way to mock functions or modules, a great command line interface, and automatic test isolation (each test file will run in its own environment). Jest also automatically mocks dependencies when running your tests, which makes it easier to isolate what you're testing.

In a typical testing scenario with Jest in a React application, you'd write something like this:

```jsx
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';

test('renders welcome message', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/Welcome to my App!/i);
expect(linkElement).toBeInTheDocument();
});
```

In this sample test, a component (<App />) is being rendered and then it checks if a certain text ("Welcome to my App!") is present in the document. If the test goes as expected, it means that the component is being rendered correctly and showing the intended message.

bottom of page