Skip to content

Instantly share code, notes, and snippets.

@aljorgevi
Last active June 18, 2022 12:13
Show Gist options
  • Save aljorgevi/6fa0fdc179f0d751736dbc898c808ba7 to your computer and use it in GitHub Desktop.
Save aljorgevi/6fa0fdc179f0d751736dbc898c808ba7 to your computer and use it in GitHub Desktop.
Vite + Jest + React Testing Library

Jest + React Testing Library

React + Vite

  1. Instalaciones:
npm install -D jest babel-jest @babel/preset-env @babel/preset-react 
npm install -D @testing-library/react @types/jest jest-environment-jsdom
  1. if Fetch API:
npm install -D whatwg-fetch
  1. package.json
"scripts: {
  ...
  "test": "jest --watchAll"
  1. babel.config.js
module.exports = {
    presets: [
        [ '@babel/preset-env', { targets: { esmodules: true } } ],
        [ '@babel/preset-react', { runtime: 'automatic' } ],
    ],
};
  1. Jest config & setup:

jest.config.js

module.exports = {
    testEnvironment: 'jest-environment-jsdom',
    setupFiles: ['./jest.setup.js']
}

jest.setup.js

import 'whatwg-fetch'; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment