Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3de0a83

Browse files
committedNov 17, 2021
initial commit.
0 parents  commit 3de0a83

24 files changed

+14806
-0
lines changed
 

Diff for: ‎.eslintrc.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:react/recommended"
11+
],
12+
"parserOptions": {
13+
"ecmaFeatures": {
14+
"jsx": true
15+
},
16+
"ecmaVersion": 12,
17+
"sourceType": "module"
18+
},
19+
"plugins": [
20+
"react"
21+
],
22+
"rules": {
23+
}
24+
}

Diff for: ‎.gitignore

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Snowpack dependency directory (https://snowpack.dev/)
45+
web_modules/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
.parcel-cache
78+
79+
# Next.js build output
80+
.next
81+
out
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and not Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port
107+
108+
# Stores VSCode versions used for testing VSCode extensions
109+
.vscode-test
110+
111+
# yarn v2
112+
.yarn/cache
113+
.yarn/unplugged
114+
.yarn/build-state.yml
115+
.yarn/install-state.gz
116+
.pnp.*
117+
118+
.DS_Store
119+
.vscode
120+
# Logs
121+
logs
122+
*.log
123+
npm-debug.log*
124+
yarn-debug.log*
125+
yarn-error.log*
126+
lerna-debug.log*
127+
.pnpm-debug.log*
128+
129+
# Diagnostic reports (https://nodejs.org/api/report.html)
130+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
131+
132+
# Runtime data
133+
pids
134+
*.pid
135+
*.seed
136+
*.pid.lock
137+
138+
# Directory for instrumented libs generated by jscoverage/JSCover
139+
lib-cov
140+
141+
# Coverage directory used by tools like istanbul
142+
coverage
143+
*.lcov
144+
145+
# nyc test coverage
146+
.nyc_output
147+
148+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
149+
.grunt
150+
151+
# Bower dependency directory (https://bower.io/)
152+
bower_components
153+
154+
# node-waf configuration
155+
.lock-wscript
156+
157+
# Compiled binary addons (https://nodejs.org/api/addons.html)
158+
build/Release
159+
160+
# Dependency directories
161+
node_modules/
162+
jspm_packages/
163+
164+
# Snowpack dependency directory (https://snowpack.dev/)
165+
web_modules/
166+
167+
# TypeScript cache
168+
*.tsbuildinfo
169+
170+
# Optional npm cache directory
171+
.npm
172+
173+
# Optional eslint cache
174+
.eslintcache
175+
176+
# Microbundle cache
177+
.rpt2_cache/
178+
.rts2_cache_cjs/
179+
.rts2_cache_es/
180+
.rts2_cache_umd/
181+
182+
# Optional REPL history
183+
.node_repl_history
184+
185+
# Output of 'npm pack'
186+
*.tgz
187+
188+
# Yarn Integrity file
189+
.yarn-integrity
190+
191+
# dotenv environment variables file
192+
.env
193+
.env.test
194+
.env.production
195+
196+
# parcel-bundler cache (https://parceljs.org/)
197+
.cache
198+
.parcel-cache
199+
200+
# Next.js build output
201+
.next
202+
out
203+
204+
# Nuxt.js build / generate output
205+
.nuxt
206+
dist
207+
208+
# Gatsby files
209+
.cache/
210+
# Comment in the public line in if your project uses Gatsby and not Next.js
211+
# https://nextjs.org/blog/next-9-1#public-directory-support
212+
# public
213+
214+
# vuepress build output
215+
.vuepress/dist
216+
217+
# Serverless directories
218+
.serverless/
219+
220+
# FuseBox cache
221+
.fusebox/
222+
223+
# DynamoDB Local files
224+
.dynamodb/
225+
226+
# TernJS port file
227+
.tern-port
228+
229+
# Stores VSCode versions used for testing VSCode extensions
230+
.vscode-test
231+
232+
# yarn v2
233+
.yarn/cache
234+
.yarn/unplugged
235+
.yarn/build-state.yml
236+
.yarn/install-state.gz
237+
.pnp.*
238+
node_modules

Diff for: ‎README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Unit Testing React Module Project: Stranger Things
2+
3+
This module explored passing props into test components, rerendering components and using mocks to both monitor functional props and override the functionality of external modules. In this project, you will practice each of these practices in the testing of an application that displays TV show data.
4+
5+
## Objectives
6+
- Understand how to test the effects of passing specific props into a component
7+
- Understand how to monitor the behavior of functional mock props.
8+
- Understand how and when to test using the rerender method
9+
- Learn how to mock the use an external module
10+
11+
## Introduction
12+
As a developer, you will often be asked to write tests for the feature you are building and even on features other developers have built. In this project, we will mimic a situation where you are asked to test someone else's code.
13+
14+
Get the project fired up and start using it as a user would. Try to go through the user sequences for this feature that you think users would go through. Once you have those in mind, you will have an idea of what to test in your application.
15+
16+
![Stranger Example](project_example.gif)
17+
18+
***Make sure to complete your tasks one at a time and complete test each task before proceeding forward.***
19+
20+
## Instructions
21+
### Task 1: Project Set Up
22+
* [ ] Create a forked copy of this project.
23+
* [ ] Clone your OWN version of the repository in your terminal
24+
* [ ] cd into the project base directory `cd web-module-project-reducer-pattern`
25+
* [ ] Download project dependencies by running `npm install`
26+
* [ ] Start up the app using `npm start`
27+
- [ ] With each saved change in your editor, the test runner will re-run all the tests
28+
- [ ] **IMPORTANT** If a test fails, use the test runner's error messages to find out why it is failing
29+
30+
### Task 2: Project Requirements
31+
#### The Episode Component
32+
> *This component displays a single episode worth of data. To test it, let's try our some different varieties on what we should pass into our component's props.*
33+
34+
* [ ] Complete a test that shows the Episode component renders. Pass in the provided example episode data as a test prop.
35+
* [ ] Modify the test data to display a specific summary statement. Complete a test that shows that the summary value passed in to the Episode component displays as expected. **Use at least then 3 different types of expect statements to test the the existence of the summary value.**
36+
* [ ] The episode component displays a default value ('./stranger_things.png') when a image url is not provided. Create a new piece of test data with the image property set to `null`. Test that the alt tag of the image displayed is set to './stranger_things.png'.
37+
38+
### The Show Component
39+
> *This component holds all general information on our featured show. Here we will once again work with data props, mock a function for testing and rerender our component for a change in data.*
40+
41+
* [ ] Build an example data structure that contains the show data in the correct format. A show should contain a name, a summary and an array of seasons, each with a id, name and an (empty) list of episodes within them. Use console.logs within the client code if you need to to verify the structure of show data.
42+
* [ ] Test that the Show component renders when your test data is passed in through show prop and "none" is passed in through selectedSeason prop.
43+
* [ ] Test that the Loading component displays when null is passed into the show prop (look at the Loading component to see how to test for it's existence)
44+
* [ ] Test that when your test data is passed through the show prop, the same number of season select options appear as there are seasons within your test data.
45+
* [ ] Test that when an item is selected, the handleSelect function is called. Look at your code to see how to get access to the select DOM element and [userEvent reference materials](https://testing-library.com/docs/ecosystem-user-event/) to see how to trigger a selection.
46+
* [ ] Test that the episode component DOES NOT render when the selectedSeason props is "none" and DOES render the episode component when the selectedSeason prop has a valid season index.
47+
48+
### The Display Component
49+
> *This component holds the state values of the application and handles api calls. In this component's tests, you work with mocking external modules and working with async / await / waitFor*
50+
* [ ] Test that the Display component renders without any passed in props.
51+
* [ ] Rebuild or copy the show test data element as used in the previous set of tests.
52+
* [ ] Test that when the fetch button is pressed, the show component will display. Make sure to account for the api call and change of state in building your test.
53+
* [ ] Test that when the fetch button is pressed, the amount of select options rendered is equal to the amount of seasons in your test data.
54+
* [ ] Notice the optional functional prop passed in to the Display component client code. Test that when the fetch button is pressed, this function is called.
55+
56+
### Stretch goals
57+
58+
- Add in a testing suite for the episodes component.
59+
60+
- Look up the `TVMaze` API. Add a dropdown with the titles of some other popular shows. Add the user sequence of choosing a different show to fetch data for different shows.
61+
62+
- Add React Router, and add the functionality to click an episode and navigate to an episode page.

Diff for: ‎babel.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
env: {
3+
testing: { // matches the `NODE_ENV=testing` in "test" script in package.json
4+
plugins: [
5+
'@babel/plugin-transform-runtime',
6+
],
7+
presets: [
8+
['@babel/preset-react'],
9+
[
10+
'@babel/preset-env',
11+
{
12+
modules: 'commonjs',
13+
debug: false
14+
}
15+
]
16+
]
17+
}
18+
}
19+
};

0 commit comments

Comments
 (0)
Please sign in to comment.