React Testing Library(RTL)

Basic concept

React beginners often confuse the tools for testing in React. React Testing Library is not an alternative to Jest, because they need each other and every one of them has a clear task.

If you are using create-react-app, Jest (and React Testing Library) comes by default with the installation. Let's look at the following functions for your tests:

describe('my function or component', () => {
  test('does the following', () => {
      expect(2 + 4).toBe(6);
  });
});
  • Whereas the describe-block is the test suite

  • the test-block (which also can be named it instead of test) is the test case. A test suite can have multiple test cases and a test case doesn't have to be in a test suite.

  • What you put into the test cases are called assertions (e.g. expect in Jest) which either turn out to be successful (green) or erroneous (red).

上一篇:React Ant Design+Node.js Express+Mysql实现后端分页


下一篇:Double—Ten alpha冲刺9