-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a basic framework for testing and a single demo test #133
base: master
Are you sure you want to change the base?
Changes from 2 commits
0f914e5
95cccf9
26a9a2f
648896d
9f32d07
fef0131
bdb5e60
c84051a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
setupFiles: ["./src/setupTests.ts"], | ||
moduleNameMapper: { | ||
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": | ||
"<rootDir>/mocks/fileMock.js", | ||
"\\.(css|less)$": "<rootDir>/mocks/fileMock.js" | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = ""; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,11 +64,19 @@ | |
"utility-types": "^3.4.1" | ||
}, | ||
"devDependencies": { | ||
"@types/enzyme": "^3.9.1", | ||
"@types/enzyme-adapter-react-16": "^1.0.5", | ||
"enzyme": "^3.9.0", | ||
"enzyme-adapter-react-16": "^1.11.2", | ||
"husky": "^1.3.1", | ||
"jest": "^24.5.0", | ||
"jest-dom": "^3.1.3", | ||
"lint-staged": "^8.1.5", | ||
"react-testing-library": "^6.0.1", | ||
"stylelint": "^9.10.1", | ||
"stylelint-config-recommended-scss": "^3.2.0", | ||
"stylelint-scss": "^3.5.4" | ||
"stylelint-scss": "^3.5.4", | ||
"ts-jest": "^24.0.0" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
|
@@ -96,7 +104,7 @@ | |
"start-js": "react-scripts-ts start", | ||
"start": "npm-run-all -p watch-css start-js", | ||
"build": "yarn build-css && react-scripts-ts build && ncp build dist", | ||
"test": "react-scripts-ts test --env=jsdom", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you replace this with the jest command? Doesn't react-scripts-ts use jest for testing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be some problem with the jest config of react-scripts-ts (jestjs/jest#6393). It doesn't really matter since both commands just run jest in watch mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not exactly, react-scripts-ts runs ts-jest not jest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using ts-jest as a preset in the jest config |
||
"test": "jest --watch", | ||
"eject": "react-scripts-ts eject", | ||
"deploy": "yarn build", | ||
"postinstall": "node postinstall.js" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { shallow } from "enzyme"; | ||
import React from "react"; | ||
import FixmeNavbar from "./FixMeNavbar"; | ||
|
||
describe("<FixmeNavBar />", () => { | ||
it("renders without errors", () => { | ||
shallow(<FixmeNavbar />); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Enzyme from "enzyme"; | ||
import Adapter from "enzyme-adapter-react-16"; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need enzyme? Doesn't react-testing-library cover our use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also have preferred to use react-testing-library. But I had trouble getting it to work with typescript. Its documentation and examples are not as good or mature as enzyme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think jest along with react-testing-library serves the purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the approach that react-testing library takes to testing. But like I said, it is not as well documented or mature as enzyme is