Coder Social home page Coder Social logo

testを書いてみる about ifcjs-react HOT 4 OPEN

ktaroabobon avatar ktaroabobon commented on September 4, 2024
testを書いてみる

from ifcjs-react.

Comments (4)

ktaroabobon avatar ktaroabobon commented on September 4, 2024

Reactのtest方法(公式)

コンポーネントのテスト方法

大きく分けて2つ:

  1. コンポーネントツリーのレンダー
     - シンプルなテスト環境で行い、その結果を検証
  2. アプリケーション全体の動作
     - ブラウザ同等の環境で検証する(end2endテスト)

どちらかというと前者にフォーカスしたテストを紹介する

トレードオフ

  • 実行速度 vs 環境の現実度
  • モックの粒度

推奨ツール

リンク

公式:https://ja.reactjs.org/docs/testing.html

from ifcjs-react.

ktaroabobon avatar ktaroabobon commented on September 4, 2024

参考になりそうなリンク一覧

from ifcjs-react.

ktaroabobon avatar ktaroabobon commented on September 4, 2024

環境構築

yarn add --dev jest
yarn add --dev @types/jest
yarn add --dev ts-jest

@testing-library/react
React コンポーネントテストのためのユーティリティライブラリーです。
@testing-library/jest-dom
Jest のマッチャーを拡張するユーティリティライブラリーです。
@testing-library/user-event
実際のイベントをシミュレートするためのユーティリティライブラリーです。
@testing-library/react-hooks
React が提供する Hooks テストのためのユーティリティライブラリーです。

yarn add --dev @testing-library/react
yarn add --dev @testing-library/jest-dom
yarn add --dev @testing-library/user-event
yarn add --dev @testing-library/react-hooks
yarn add --dev jest-environment-jsdom

from ifcjs-react.

ktaroabobon avatar ktaroabobon commented on September 4, 2024

ts-jestで外部ライブラリがimportできない
-> babelを使う

yarn add --dev babel-jest @babel/core @babel/preset-env
yarn add --dev @babel/preset-typescript
  • babel.config.jsを作成する
module.exports = {
  presets: [
    ['@babel/preset-env', {targets: {node: 'current'}}],
    '@babel/preset-typescript',
  ],
};

参考

from ifcjs-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.