Skip to content

Commit 827a26a

Browse files
jest done
1 parent 3eaa4f3 commit 827a26a

File tree

7 files changed

+2897
-44
lines changed

7 files changed

+2897
-44
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["next/babel"]
3+
}

jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
roots: ['<rootDir>'],
3+
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx'],
4+
testPathIgnorePatterns: ['<rootDir>[/\\\\](node_modules|.next)[/\\\\]'],
5+
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(ts|tsx)$'],
6+
transform: {
7+
'^.+\\.(ts|tsx)$': 'babel-jest',
8+
},
9+
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
10+
moduleNameMapper: {
11+
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
12+
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/test/__mocks__/fileMock.js',
13+
},
14+
};

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"tsc": "tsc --project tsconfig.json --pretty --noEmit",
1010
"lint": "eslint --ext ts,tsx --fix",
1111
"pretti": "prettier --config ./.prettierrc.js -w ./src",
12-
"postinstall": "husky install"
12+
"postinstall": "husky install",
13+
"test": "jest"
1314
},
1415
"dependencies": {
1516
"date-fns": "^2.11.1",
@@ -21,19 +22,27 @@
2122
"remark-html": "^12.0.0"
2223
},
2324
"devDependencies": {
25+
"@babel/core": "^7.14.3",
26+
"@types/jest": "^26.0.23",
2427
"@types/node": "^15.6.0",
2528
"@types/react": "^17.0.6",
29+
"@types/react-test-renderer": "^17.0.1",
2630
"@typescript-eslint/eslint-plugin": "^4.24.0",
2731
"@typescript-eslint/parser": "^4.24.0",
32+
"babel-jest": "^26.6.3",
2833
"eslint": "^7.27.0",
2934
"eslint-config-prettier": "^8.3.0",
3035
"eslint-plugin-jsx-a11y": "^6.4.1",
3136
"eslint-plugin-prettier": "^3.4.0",
3237
"eslint-plugin-react": "^7.23.2",
3338
"eslint-plugin-react-hooks": "^4.2.0",
3439
"husky": "^6.0.0",
40+
"identity-obj-proxy": "^3.0.0",
41+
"jest": "^26.6.3",
42+
"jest-watch-typeahead": "^0.6.3",
3543
"lint-staged": "^11.0.0",
3644
"prettier": "^2.3.0",
45+
"react-test-renderer": "^17.0.2",
3746
"typescript": "^4.2.4"
3847
}
3948
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`HomePage should match the snapshot 1`] = `
4+
<div
5+
className="container"
6+
>
7+
<header
8+
className="header"
9+
>
10+
<div
11+
style={
12+
Object {
13+
"boxSizing": "border-box",
14+
"display": "inline-block",
15+
"margin": 0,
16+
"maxWidth": "100%",
17+
"overflow": "hidden",
18+
"position": "relative",
19+
}
20+
}
21+
>
22+
<div
23+
style={
24+
Object {
25+
"boxSizing": "border-box",
26+
"display": "block",
27+
"maxWidth": "100%",
28+
}
29+
}
30+
>
31+
<img
32+
alt=""
33+
aria-hidden={true}
34+
role="presentation"
35+
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTQ0IiBoZWlnaHQ9IjE0NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiLz4="
36+
style={
37+
Object {
38+
"border": "none",
39+
"display": "block",
40+
"margin": 0,
41+
"maxWidth": "100%",
42+
"padding": 0,
43+
}
44+
}
45+
/>
46+
</div>
47+
<img
48+
alt="[Your Name]"
49+
className="borderCircle"
50+
decoding="async"
51+
src="/_next/image?url=%2Fimages%2Fprofile.jpg&w=384&q=75"
52+
srcSet="/_next/image?url=%2Fimages%2Fprofile.jpg&w=256&q=75 1x, /_next/image?url=%2Fimages%2Fprofile.jpg&w=384&q=75 2x"
53+
style={
54+
Object {
55+
"border": "none",
56+
"bottom": 0,
57+
"boxSizing": "border-box",
58+
"display": "block",
59+
"height": 0,
60+
"left": 0,
61+
"margin": "auto",
62+
"maxHeight": "100%",
63+
"maxWidth": "100%",
64+
"minHeight": "100%",
65+
"minWidth": "100%",
66+
"objectFit": undefined,
67+
"objectPosition": undefined,
68+
"padding": 0,
69+
"position": "absolute",
70+
"right": 0,
71+
"top": 0,
72+
"width": 0,
73+
}
74+
}
75+
/>
76+
</div>
77+
<h1
78+
className="heading2Xl"
79+
>
80+
[Your Name]
81+
</h1>
82+
</header>
83+
<main>
84+
<section
85+
className="headingMd"
86+
>
87+
<p>
88+
[Your Self Introduction]
89+
</p>
90+
<p>
91+
(This is a sample website - you’ll be building a site like this in
92+
93+
<a
94+
href="https://nextjs.org/learn"
95+
>
96+
our Next.js tutorial
97+
</a>
98+
.)
99+
</p>
100+
</section>
101+
<section
102+
className="headingMd padding1px"
103+
>
104+
<h2
105+
className="headingLg"
106+
>
107+
Blog
108+
</h2>
109+
<ul
110+
className="list"
111+
/>
112+
</section>
113+
</main>
114+
</div>
115+
`;

src/pages/index.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import renderer from 'react-test-renderer';
2+
import HomePage from '.';
3+
4+
describe('HomePage', () => {
5+
it('should match the snapshot', () => {
6+
const tree = renderer.create(<HomePage allPostsData={[]} />).toJSON();
7+
expect(tree).toMatchSnapshot();
8+
});
9+
});

src/pages/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface HomeProps {
1212
allPostsData: Post[];
1313
}
1414

15-
export const Home: React.FC<HomeProps> = ({ allPostsData }) => {
15+
export const HomePage: React.FC<HomeProps> = ({ allPostsData }) => {
1616
return (
1717
<Layout home>
1818
<Head>
@@ -56,4 +56,4 @@ export const getStaticProps: GetStaticProps<HomeProps> = async () => {
5656
};
5757
};
5858

59-
export default Home;
59+
export default HomePage;

0 commit comments

Comments
 (0)