0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ReactのJestのテストでエラー Consider adding an error boundary to your tree to customize error handling behavior. Visit https://fb.me/react-error-boundaries to learn more about error boundaries.

Posted at

背景

Reactアプリ開発のテストをJestで実施しているのだけど、「Consider adding an error boundary to your tree to customize error handling behavior.Visit https://fb.me/react-error-boundaries to learn more about error boundaries.」というエラーに悩まされたので解決方法をまとめておく。

開発言語 (バージョン情報)

React.js (17.0.2)
Next.js (11.1.2)
TypeScript (4.4.3)
Jest (27.2.2)

解決策

「react-test-renderer」ではなく「Testing Library」を使用する。

sample.spec.tsx
import React from 'react';
import App from './App';
import { render } from '@testing-library/react';

describe('test 1', () => {

  it('test case 1', () => {
    const { container } = render(<App />);
    expect(container).toMatchSnapshot();
  });

});

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?