Skip to content

Commit 3e2f2e8

Browse files
committed
Visual Testing
1 parent 79c150a commit 3e2f2e8

File tree

8 files changed

+11679
-8099
lines changed

8 files changed

+11679
-8099
lines changed

package-lock.json

Lines changed: 11645 additions & 8075 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^16.13.1",
1818
"react-dom": "^16.13.1",
1919
"react-router-dom": "^5.2.0",
20-
"react-scripts": "3.4.1",
20+
"react-scripts": "^4.0.1",
2121
"typescript": "~3.7.2"
2222
},
2323
"scripts": {
@@ -40,5 +40,13 @@
4040
"last 1 firefox version",
4141
"last 1 safari version"
4242
]
43+
},
44+
"devDependencies": {
45+
"@types/jest-image-snapshot": "^4.1.3",
46+
"@types/jsdom-screenshot": "^3.2.0",
47+
"jest-image-snapshot": "^4.3.0",
48+
"jest-transform-css": "^2.1.0",
49+
"jest-transform-file": "^1.1.1",
50+
"jsdom-screenshot": "^4.0.0"
4351
}
4452
}

src/App.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@
3636
transform: rotate(360deg);
3737
}
3838
}
39+
40+
.paragraph-cls {
41+
text-transform: capitalize;
42+
}

src/App.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3+
import { generateImage } from 'jsdom-screenshot';
34
import App from './App';
45

5-
test('renders learn react link', () => {
6-
const { getByText } = render(<App />);
7-
const linkElement = getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
6+
test('renders learn react link', async () => {
7+
render(<App />);
8+
9+
const screenshot = await generateImage();
10+
expect(screenshot).toMatchImageSnapshot();
911
});

src/App.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import React from 'react';
2-
import ExchangeRates from './components/ExchangeRates';
32
import logo from './logo.svg';
43
import './App.css';
5-
import {
6-
Link
7-
} from "react-router-dom";
8-
import { Can } from './rules/Can';
9-
import { Article } from "./rules/entities";
10-
function App() {
11-
12-
const article = new Article({ published: true });
134

5+
function App() {
146
return (
157
<div className="App">
168
<header className="App-header">
179
<img src={logo} className="App-logo" alt="logo" />
18-
<p>
19-
Edit <code>src/App.tsx</code> and save to reload.
20-
</p>
10+
<p className="paragraph-cls">Lorem ipsum dolor sit amet consectetur adipisicing elit. Atque ex perferendis maxime voluptatem molestiae? Qui cupiditate asperiores ipsa nesciunt, iusto minima voluptatem alias sit porro sunt ad veritatis reiciendis? Deserunt.</p>
2111
<a
2212
className="App-link"
2313
href="https://reactjs.org"
@@ -26,11 +16,6 @@ function App() {
2616
>
2717
Learn React
2818
</a>
29-
<Link to="/books">Books</Link>
30-
<Link to="/todos">Todos</Link>
31-
<Can I="read" a={article}>
32-
{ () => <ExchangeRates /> }
33-
</Can>
3419
</header>
3520
</div>
3621
);
33 KB
Loading

src/setupTests.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
// allows you to do things like:
33
// expect(element).toHaveTextContent(/react/i)
44
// learn more: https://github.com/testing-library/jest-dom
5-
import '@testing-library/jest-dom/extend-expect';
5+
import "@testing-library/jest-dom/extend-expect";
6+
import { setDefaultOptions } from "jsdom-screenshot";
7+
import { toMatchImageSnapshot } from "jest-image-snapshot";
8+
9+
setDefaultOptions({
10+
serve: ["src"],
11+
});
12+
expect.extend({ toMatchImageSnapshot });
13+
14+
// give tests more time as taking screenshots takes a while
15+
jest.setTimeout(10000);

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"isolatedModules": true,
1919
"noEmit": true,
2020
"jsx": "react",
21-
"noImplicitAny": false
21+
"noImplicitAny": false,
22+
"noFallthroughCasesInSwitch": true
2223
},
2324
"include": [
2425
"src",

0 commit comments

Comments
 (0)