This project was bootstrapped with Create React App.
Lifting State up example - https://reactjs.org/docs/lifting-state-up.html
Demo app features
- Ported Javascript to Typescript
- Unit test using jest
- Interaction test using Enzyme
- Added storybook
- Snapshot testing with storyshot addon to automated snapshot testing for stories
- Automated Visual Testing using storybook and puppeteer
Open http://localhost:3000 to view it in the browser.
Launches the test runner in the interactive watch mode.
To run the Automated visual testing. For testing changed the text it is captured in Visual testing and stored as image in /src/tests/integration/image_snapshots/diff_output/ directory
To run the test coverage
npx create-react-app my-app --typescript
or
yarn create react-app my-app --typescript
npm i --save-dev enzyme enzyme-adapter-react-16
or
yarn add enzyme enzyme-adapter-react-16 -d
and create setupConfig.js by following https://airbnb.io/enzyme/
npx -p @storybook/cli sb init --type react
Add storybook addons
yarn add --dev @storybook/addon-storyshots react-test-renderer require-context.macro
- create storybook.test.js
// src/storybook.test.js
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();
- add config.js
// .storybook/config.js
import { configure } from '@storybook/react';
import requireContext from 'require-context.macro';
import '../src/index.css';
const req = requireContext('../src/components', true, /\.stories\.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
configure(loadStories, module);
Reference:
- https://storybook.js.org/docs/guides/guide-react/
- https://www.learnstorybook.com/react/en/simple-component/
yarn add puppeteer jest-puppeteer jest-image-snapshot start-server-and-test --dev
Follow for other configurations:https://storybook.js.org/docs/testing/automated-visual-testing/#example-using-puppeteer-and-jest