Skip to content

Commit 9fc6ca3

Browse files
committed
init jest
1 parent ee7703b commit 9fc6ca3

File tree

9 files changed

+2198
-39
lines changed

9 files changed

+2198
-39
lines changed

.babelrc

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
{
2-
"presets": ["@babel/preset-react", "@babel/typescript"],
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"targets": {
7+
"browsers": ["last 2 versions"]
8+
}
9+
}
10+
],
11+
"@babel/typescript",
12+
"@babel/preset-react"
13+
],
314
"plugins": ["@babel/proposal-class-properties", "@babel/proposal-object-rest-spread"]
415
}

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
"dev": "run-p dev:*",
1010
"dev:webpack": "webpack-dev-server --mode development --content-base ./site",
1111
"dev:ts": "tsc --watch --preserveWatchOutput",
12-
"build": "yarn run clean && tsc && webpack --mode production"
12+
"test": "jest",
13+
"build": "yarn run clean && tsc && yarn run test && webpack --mode production"
1314
},
1415
"devDependencies": {
1516
"@babel/core": "^7.2.2",
1617
"@babel/plugin-proposal-class-properties": "^7.3.0",
1718
"@babel/plugin-proposal-object-rest-spread": "^7.3.1",
19+
"@babel/preset-env": "^7.3.1",
1820
"@babel/preset-react": "^7.0.0",
1921
"@babel/preset-typescript": "^7.1.0",
22+
"@types/jest": "^23.3.13",
2023
"@types/react": "^16.7.22",
2124
"@types/react-dom": "^16.0.11",
2225
"babel-loader": "^8.0.5",
26+
"jest": "^24.0.0",
2327
"npm-run-all": "^4.1.5",
2428
"typescript": "^3.3.0-rc",
2529
"webpack": "5.0.0-alpha.9",

src/Foo.ts

-1
This file was deleted.

src/Sum.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const sum = (x: number, y: number) => x + y

src/__test__/Sum.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { sum } from '../Sum'
2+
3+
test('adds 1 + 2 to equal 3', () => {
4+
expect(sum(1, 2)).toBe(3)
5+
})

src/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33

4-
import { add } from 'Foo'
4+
import { sum } from 'Sum'
55
import Example from 'lib/Example'
66

77
enum Check {
@@ -11,7 +11,7 @@ enum Check {
1111

1212
const Foo = () => (
1313
<div style={{ fontSize: 24 }}>
14-
Hello: {Check.Bar} | {add(3, 2)}
14+
Hello: {Check.Bar} | {sum(3, 2)}
1515
<Example initialCounter={2} />
1616
</div>
1717
)

src/lib/Example.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface Props {
77
export default function Example({ initialCounter }: Props) {
88
// Declare a new state variable, which we'll call "count"
99
const [count, setCount] = useState(initialCounter)
10+
console.log('render: ', count)
1011

1112
return (
1213
<div>

yarn.lock

+2,163-34
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)