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

feat: add test setup based on jest and testing-library #12

Merged
merged 4 commits into from
May 24, 2020
Merged
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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-react","@babel/preset-env"]
}
8,725 changes: 5,685 additions & 3,040 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "parcel build index.html --no-cache",
"lint": "eslint 'src/**/*.js' --quiet --fix",
"clean": "rimraf ./dist ./.cache",
"ci:lint": "eslint 'src/**/*.js' -c ./.eslintrc.js"
"ci:lint": "eslint 'src/**/*.js' -c ./.eslintrc.js",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"codemirror": "5.53.2",
Expand All @@ -21,11 +23,17 @@
"react-dom": "^16.13.1"
},
"devDependencies": {
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@testing-library/dom": "^7.5.7",
"@testing-library/react": "^10.0.4",
"@testing-library/user-event": "^10.3.5",
"babel-eslint": "^10.1.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.2",
"parcel-bundler": "^1.6.1",
"postcss-easy-import": "^3.0.0",
Expand All @@ -34,6 +42,15 @@
"rimraf": "^3.0.2",
"tailwindcss": "^1.4.6"
},
"jest": {
"verbose": true,
"moduleNameMapper": {
"\\.(jpg|jpeg|png|svg)$": "<rootDir>/src/__mocks__/fileMock.js"
},
"setupFilesAfterEnv": [
"./tests/setupTests.js"
]
},
"keywords": [],
"husky": {
"hooks": {
Expand Down
1 change: 1 addition & 0 deletions src/__mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
9 changes: 9 additions & 0 deletions src/components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import App from './App';
import { renderWithContext } from '../../tests/utils/render';

describe('App', () => {
it('should not throw on render', () => {
renderWithContext(<App />);
});
});
14 changes: 14 additions & 0 deletions tests/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as TestingLibraryDom from '@testing-library/dom';

window.TestingLibraryDom = TestingLibraryDom;

if (window.document) {
window.document.createRange = () => ({
setStart: () => {},
setEnd: () => {},
getBoundingClientRect: () => {
return { right: 0 };
},
getClientRects: () => [],
});
}
9 changes: 9 additions & 0 deletions tests/utils/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import { AppContextProvider } from '../../src/components/Context';

function renderWithContext(component, ...args) {
return render(<AppContextProvider>{component}</AppContextProvider>, ...args);
}

export { renderWithContext };