Skip to content

Instantly share code, notes, and snippets.

@machelinos
Last active September 26, 2022 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machelinos/e2f0bfe39838b5373f740585dfd63835 to your computer and use it in GitHub Desktop.
Save machelinos/e2f0bfe39838b5373f740585dfd63835 to your computer and use it in GitHub Desktop.
Vite - Jest initial setup
React + Vite projects
npm install jest babel-jest @babel/preset-env @babel/preset-react --save-dev
npm install @testing-library/react @types/jest jest-environment-jsdom --save-dev
--------------
Whwen using fetch
npm install whatwg-fetch --save-dev
------------.
Create babrl congig babe.config.cjs
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
['@babel/preset-react', {runtime: 'automatic'}]
],
};
-----------------------
Create jest.setup.js
import { fetch } from "whatwg-fetch";
----------------------
Create jest.config.cjs
module.exports = {
testEnvironment: 'jest-environment-jsdom',
setupFiles: ['./jest.setup.js']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment