integrate jest and react-testing-library with test coverage

This commit is contained in:
Suren Atoyan 2019-06-19 14:08:45 +04:00
parent 7899414288
commit f8a0144484
6 changed files with 2068 additions and 44 deletions

View File

@ -8,7 +8,7 @@
"lint": "npx eslint src",
"build": "npx babel src --out-dir lib",
"prepublish": "npm test && npm run lint && npm run build",
"test": "echo \"Error: no test specified\" && exit 0"
"test": "npx jest"
},
"repository": {
"type": "git",
@ -39,7 +39,9 @@
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"@testing-library/react": "^8.0.1",
"babel-eslint": "9.x",
"babel-jest": "^24.8.0",
"eslint": "5.x",
"eslint-config-react-app": "^4.0.1",
"eslint-plugin-flowtype": "2.x",
@ -48,7 +50,10 @@
"eslint-plugin-react": "7.x",
"eslint-plugin-react-hooks": "1.5.0",
"husky": "^2.4.1",
"react": "^16.8.6"
"jest": "^24.8.0",
"jest-dom": "^3.5.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
"babel": {
"presets": [
@ -68,5 +73,6 @@
"hooks": {
"pre-commit": "npm test && npm run lint"
}
}
},
"dependencies": {}
}

View File

@ -0,0 +1,91 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Editor /> should check render with snapshot 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<section
style="display: flex; position: relative; height: 100%;"
>
<div
style="display: flex; height: 100%; width: 100%; justify-content: center; align-items: center;"
>
Loading...
</div>
<div
style="width: 100%; display: none;"
/>
</section>
</div>
<script
src="/monaco-editor/vs/loader.js"
/>
</body>,
"container": <div>
<section
style="display: flex; position: relative; height: 100%;"
>
<div
style="display: flex; height: 100%; width: 100%; justify-content: center; align-items: center;"
>
Loading...
</div>
<div
style="width: 100%; display: none;"
/>
</section>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

14
src/Editor/index.spec.js Normal file
View File

@ -0,0 +1,14 @@
import React from 'react';
import Editor from '.';
import { render } from '@testing-library/react';
import 'jest-dom/extend-expect';
describe('<Editor />', () => {
it('should check render with snapshot', () => {
const component = render(
<Editor />,
);
expect(component).toMatchSnapshot();
});
});

View File

@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Loading /> should check render with snapshot 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
<div
style="display: flex; height: 100%; width: 100%; justify-content: center; align-items: center;"
/>
</div>
</body>,
"container": <div>
<div
style="display: flex; height: 100%; width: 100%; justify-content: center; align-items: center;"
/>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

36
src/Loading/index.spec.js Normal file
View File

@ -0,0 +1,36 @@
import React from 'react';
import Loading from '.';
import { render } from '@testing-library/react';
import 'jest-dom/extend-expect';
describe('<Loading />', () => {
it('should check render with snapshot', () => {
const component = render(
<Loading />,
);
expect(component).toMatchSnapshot();
});
it('should check is it wrapped with <div />', () => {
const component = render(
<Loading />,
);
const { container } = component;
expect(container.firstChild.tagName).toBe('DIV');
});
it('should check content', () => {
const content = 'Loading...';
const component = render(
<Loading content={content} />,
);
const { container } = component;
expect(container.textContent).toBe(content);
});
});

1889
yarn.lock

File diff suppressed because it is too large Load Diff