setup jest for frontend testing

This commit is contained in:
2019-03-10 17:10:31 +03:00
parent 8d112e1339
commit 693321108f
6 changed files with 2599 additions and 4 deletions

10
frontend/jest.config.js Normal file
View File

@@ -0,0 +1,10 @@
const { pathsToModuleNameMapper } = require("ts-jest/utils");
const { compilerOptions } = require("./tsconfig");
module.exports = {
preset: "ts-jest",
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: "<rootDir>/",
}),
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
};

File diff suppressed because it is too large Load Diff

View File

@@ -3,9 +3,13 @@
"scripts": { "scripts": {
"start": "parcel src/index.html", "start": "parcel src/index.html",
"build": "parcel build src/index.html", "build": "parcel build src/index.html",
"test": "echo \"Error: no tests (yet!)\"" "test": "jest"
}, },
"devDependencies": { "devDependencies": {
"@types/autoprefixer": "^9.4.0",
"@types/enzyme": "^3.9.0",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.11",
"@types/node-sass": "^3.10.32", "@types/node-sass": "^3.10.32",
"@types/parcel-bundler": "^1.10.1", "@types/parcel-bundler": "^1.10.1",
"@types/react": "^16.8.2", "@types/react": "^16.8.2",
@@ -14,10 +18,14 @@
"@types/react-router": "^4.4.3", "@types/react-router": "^4.4.3",
"@types/react-router-dom": "^4.3.1", "@types/react-router-dom": "^4.3.1",
"autoprefixer": "^9.4.7", "autoprefixer": "^9.4.7",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.10.0",
"jest": "^24.3.1",
"node-sass": "^4.11.0", "node-sass": "^4.11.0",
"parcel-bundler": "^1.11.0", "parcel-bundler": "^1.11.0",
"postcss-modules": "^1.4.1", "postcss-modules": "^1.4.1",
"redux-devtools-extension": "^2.13.8" "redux-devtools-extension": "^2.13.8",
"ts-jest": "^24.0.0"
}, },
"dependencies": { "dependencies": {
"@blueprintjs/core": "^3.13.0", "@blueprintjs/core": "^3.13.0",

View File

@@ -0,0 +1,17 @@
import { shallow } from "enzyme";
import * as React from "react";
import { NewDocumentCard } from "~Documents/NewDocumentCard";
import { DocumentsList } from "../DocumentsList";
describe("<DocumentsList />", () => {
it("should render NewDocumentCard if newDocument prop is true", () => {
const wrapper = shallow(<DocumentsList docs={[]} newDocument={true} />);
expect(wrapper.find(NewDocumentCard)).toHaveLength(1);
});
it("should render NewDocumentCard if newDocument prop is undefined", () => {
const wrapper = shallow(<DocumentsList docs={[]} />);
expect(wrapper.find(NewDocumentCard)).toHaveLength(0);
});
});

View File

@@ -0,0 +1,4 @@
import * as Enzyme from "enzyme";
import * as Adapter from "enzyme-adapter-react-16";
Enzyme.configure({ adapter: new Adapter() });

View File

@@ -14,10 +14,10 @@
"sourceMap": true, "sourceMap": true,
"noImplicitAny": true, "noImplicitAny": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"baseUrl": "./src", "baseUrl": "./",
"paths": { "paths": {
"~*": [ "~*": [
"./*" "./src/*"
] ]
} }
} }