Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jest.config.js
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"
}
};
1 change: 1 addition & 0 deletions mocks/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "";
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

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

"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": {
Expand Down Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, react-scripts-ts runs ts-jest not jest

Copy link
Author

Choose a reason for hiding this comment

The 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"
Expand Down
9 changes: 0 additions & 9 deletions src/App.test.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions src/components/FixMeNavbar/FixMeNavbar.test.tsx
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 />);
});
});
15 changes: 11 additions & 4 deletions src/components/FixMeNavbar/FixMeNavbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { OutboundLink } from "react-ga";
import { FaFacebook, FaGithub, FaTwitter } from 'react-icons/fa';
import { FaFacebook, FaGithub, FaTwitter } from "react-icons/fa";
import { NavLink } from "react-router-dom";
import { Collapse, Nav, Navbar, NavbarToggler, NavItem } from "reactstrap";
import Logo from "./logo-fixme.svg";
Expand All @@ -12,7 +12,7 @@ export interface IFixMeNavbarState {
export default class FixMeNavbar extends React.Component<
{ white?: boolean },
IFixMeNavbarState
> {
> {
public readonly state = {
isOpen: false
};
Expand All @@ -30,11 +30,18 @@ export default class FixMeNavbar extends React.Component<
<NavLink className="mr-auto navbar-brand" to="/">
<img src={Logo} className="d-inline-block align-top" alt="FixMe" />
</NavLink>
<NavbarToggler aria-label="Navigation Toggler" onClick={this.toggleNavbar} />
<NavbarToggler
aria-label="Navigation Toggler"
onClick={this.toggleNavbar}
/>
<Collapse isOpen={this.state.isOpen} navbar={true}>
<Nav className="ml-auto" navbar={true}>
<NavItem>
<NavLink className="nav-link" to="/issues">
<NavLink
className="nav-link"
to="/issues"
data-testid="issue-link"
>
Issues
</NavLink>
</NavItem>
Expand Down
4 changes: 4 additions & 0 deletions src/setupTests.ts
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() });
Loading