Jests Basic
Tue Jan 31 2023 20:21:34 GMT+0000 (Coordinated Universal Time)
Saved by
@chelobotix
npm install --save-dev jest
//json
{
"scripts": {
"test": "jest"
}
}
npm test
//mock dom
npm install --save-dev jest-environment-jsdom
/**
* @jest-environment jsdom
*/
//jest-localstorage-mock
npm i --save-dev jest-localstorage-mock
{
"name": "to-do-list",
"version": "1.0.0",
"description": "<a name=\"To Do List\"></a>",
"private": true,
"jest": {
"resetMocks": false,
"setupFiles": [
"jest-localstorage-mock"
]
},
"scripts": {
"test": "jest",...
//Babel
npm install --save-dev @babel/plugin-transform-modules-commonjs
//create a new file in the project root directory called: .babelrc with the following code in it:
{
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}
//REACT
npm install --save-dev react-test-renderer
jest --updateSnapshot
//auto complete :
npm install @types/jest
content_copyCOPY
Comments