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 all 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
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"]
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"devDependencies": {
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"react-testing-library": "^6.1.2",
"stylelint": "^9.10.1",
"stylelint-config-recommended-scss": "^3.2.0",
"stylelint-scss": "^3.5.4"
Expand Down
37 changes: 32 additions & 5 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import { ConnectedRouter } from "connected-react-router";
import { createMemoryHistory } from "history";
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import { withRouter } from "react-router";
import { cleanup, render } from "react-testing-library";
import App from "./App";
import store from "./store/createStore";

it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
afterEach(cleanup);

jest.mock("react-ga");

function renderWithRouter(
ui: any,
{
route = "/",
history = createMemoryHistory({ initialEntries: [route] })
} = {}
) {
return {
...render(
<Provider store={store}>
<ConnectedRouter history={history}>{ui}</ConnectedRouter>
</Provider>
),
// adding `history` to the returned utilities to allow us
// to reference it in our tests (just try to avoid using
// this to test implementation details).
history
};
}
test("App renders without crashing", () => {
const { container } = renderWithRouter(<App />);
expect(container).toMatchSnapshot();
});
9 changes: 6 additions & 3 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,7 +30,10 @@ 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>
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"skipLibCheck": true,
"esModuleInterop": true
},
"typeAcquisition": {
"include": ["jest"]
},
"exclude": [
"node_modules",
"build",
Expand Down
Loading