Skip to content

Commit cd2f5cb

Browse files
committed
my first commit
0 parents commit cd2f5cb

File tree

15 files changed

+17562
-0
lines changed

15 files changed

+17562
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [React testing tutorial using Jest](https://reactgo.com/react-testing-tutorial-jest/)
2+
3+
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
10+
### `npm test`
11+
12+
Launches the test runner in the interactive watch mode.<br>
13+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
14+
15+
16+
17+
### `npm run test:update`
18+
19+
It is used to update the snapshots
20+
21+
### `npm run test:coverage`
22+
23+
it is used to generate codecoverage reports

package-lock.json

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

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "react-testing",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"react": "^16.7.0",
7+
"react-dom": "^16.7.0",
8+
"react-scripts": "2.1.3"
9+
},
10+
"scripts": {
11+
"start": "react-scripts start",
12+
"build": "react-scripts build",
13+
"test": "react-scripts test",
14+
"test:update": "react-scripts test --updateSnapshot",
15+
"test:coverage": "react-scripts test --coverage",
16+
"eject": "react-scripts eject"
17+
},
18+
"eslintConfig": {
19+
"extends": "react-app"
20+
},
21+
"browserslist": [
22+
">0.2%",
23+
"not dead",
24+
"not ie <= 11",
25+
"not op_mini all"
26+
],
27+
"devDependencies": {
28+
"react-test-renderer": "^16.7.0"
29+
}
30+
}

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is added to the
13+
homescreen on Android. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>React App</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>

public/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}

src/App.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 40vmin;
8+
}
9+
10+
.App-header {
11+
background-color: #282c34;
12+
min-height: 100vh;
13+
display: flex;
14+
flex-direction: column;
15+
align-items: center;
16+
justify-content: center;
17+
font-size: calc(10px + 2vmin);
18+
color: white;
19+
}
20+
21+
.App-link {
22+
color: #61dafb;
23+
}
24+
25+
@keyframes App-logo-spin {
26+
from {
27+
transform: rotate(0deg);
28+
}
29+
to {
30+
transform: rotate(360deg);
31+
}
32+
}

src/App.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react';
2+
3+
class App extends Component {
4+
5+
state = {
6+
isActive: false
7+
}
8+
9+
handleClick = () => {
10+
this.setState({ isActive: !this.state.isActive })
11+
}
12+
13+
14+
render() {
15+
return (
16+
<div className="App">
17+
<button onClick={this.handleClick}>
18+
{this.state.isActive ? "Hide" : "Show"}
19+
</button>
20+
</div>
21+
);
22+
}
23+
}
24+
25+
export default App;

src/__tests__/App.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import App from '../App';
3+
import { create, update } from 'react-test-renderer'
4+
5+
describe('My first snapshot test', () => {
6+
test('testing app button', () => {
7+
let tree = create(<App />)
8+
expect(tree.toJSON()).toMatchSnapshot();
9+
})
10+
})
11+
12+
13+
describe("Changing our button name to Hide", () => {
14+
15+
test('toggle the button', () => {
16+
let tree = create(<App />);
17+
18+
let instance = tree.getInstance();
19+
20+
expect(instance.state.isActive).toBe(false)
21+
22+
// changing the state
23+
instance.handleClick();
24+
25+
expect(instance.state.isActive).toBe(true);
26+
27+
expect(tree.toJSON()).toMatchSnapshot()
28+
})
29+
})

0 commit comments

Comments
 (0)