uudashr / react-todo-ts

Simple React Todo App (TypeScript version)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Todo App (TypeScript Version)

Simple React Todo Application

Reference Documentation

  1. Jest Documentation
  2. Testing Library Documentation
  3. How to fetch data with React Hooks
  4. Typesafe JSON parsing

Testing

jsdom

In order to jsdom to works, se need to mock the matchMedia. Need to add script on setupTests.js

Object.defineProperty(window, 'matchMedia', {
  value: () => {
    return {
      matches: false,
      addListener: () => { },
      removeListener: () => { }
    };
  }
});

Ant Design

Add below to package.json tp ensure the antd can works with testing.

{
  "jest": {
    "transformIgnorePatterns": [
      "/node_modules/(?!antd|@ant-design|rc-.+?|@babel/runtime).+(js|jsx)$"
    ],
  }
}

Mock

Add below to package.json to ensure the test Jest mock / jest.fn() can works

{
  "jest": {
    "resetMocks": false
  }
}

Ref: jestjs/jest#9131

TypeScript Conversion

Install dependencies

npm install --save typescript @types/node @types/react @types/react-dom @types/jest

Add tsconfig.json on the project root directory

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

References:

About

Simple React Todo App (TypeScript version)


Languages

Language:TypeScript 94.4%Language:JavaScript 3.0%Language:HTML 2.0%Language:CSS 0.5%