Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0241828

Browse files
refactor(project): convert finals to typescript
refactor(project): convert entry files to typescript refactor(exercise-01): convert to typescript react refactor(exercise-01): to ts: extra credit 1. accept the step as the action refactor(exercise-01): to ts: extra credit 2. simulate setState with an object refactor(exercise-01): to ts: extra credit 3. simulate setState with object|function refactor(exercise-01): to ts: extra credit 4. traditional dispatch object refactor(pokemon.js): to ts refactor(exercise-02): to ts refactor(exercise-02): to ts: extra credit 1: use useCallback refactor(exercise-02): to ts: extra credit 2: return a memoized run function from useAsync refactor(exercise-02): to ts: extra credit 3: make safeDispatch refactor(final): move typescript final solution to `src/final-ts/` refactor(exercise-03): to ts refactor(exercise-03): to ts: extra credit 1: create a consumer hook refactor(exercise-03): to ts: extra credit 2: caching in a context provider refactor(exercise-04): to ts refactor(exercise-05): to ts refactor(exercise-06): to ts
1 parent f1c3a20 commit 0241828

36 files changed

+2044
-134
lines changed

‎package-lock.json‎

Lines changed: 6 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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"husky": "^4.3.8",
3030
"npm-run-all": "^4.1.5",
3131
"prettier": "^2.2.1",
32-
"react-scripts": "^4.0.1"
32+
"react-scripts": "^4.0.1",
33+
"typescript": "^4.1.3"
3334
},
3435
"scripts": {
3536
"start": "react-scripts start",
@@ -53,7 +54,14 @@
5354
]
5455
},
5556
"eslintConfig": {
56-
"extends": "react-app"
57+
"extends": [
58+
"react-app",
59+
"react-app/jest",
60+
"plugin:jsx-a11y/recommended"
61+
],
62+
"plugins": [
63+
"jsx-a11y"
64+
]
5765
},
5866
"babel": {
5967
"presets": [

‎src/__tests__/01.js‎ renamed to ‎src/__tests__/01.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import * as React from 'react'
22
import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
33
import {render} from '@testing-library/react'
44
import userEvent from '@testing-library/user-event'
5-
import App from '../final/01'
5+
import App from '../final/01.js'
6+
// import App from '../final-ts/01'
67
// import App from '../exercise/01'
78

89
test('clicking the button increments the count with useReducer', () => {
910
jest.spyOn(React, 'useReducer')
1011

1112
const {container} = render(<App />)
1213
const button = container.querySelector('button')
14+
if (!button) {
15+
throw new Error('button node is null')
16+
}
1317
userEvent.click(button)
1418
expect(button).toHaveTextContent('1')
1519
userEvent.click(button)

‎src/__tests__/02.extra-3.js‎ renamed to ‎src/__tests__/02.extra-3.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
33
import {render, screen} from '@testing-library/react'
44
import userEvent from '@testing-library/user-event'
55
import App from '../final/02.extra-3'
6+
// import App from '../final-ts/02.extra-3'
67
// import App from '../exercise/02'
78

9+
let fetchSpy: jest.SpyInstance
10+
let consoleErrorSpy: jest.SpyInstance
11+
812
beforeEach(() => {
9-
jest.spyOn(window, 'fetch')
10-
jest.spyOn(console, 'error')
13+
fetchSpy=jest.spyOn(window, 'fetch')
14+
consoleErrorSpy=jest.spyOn(console, 'error')
1115
})
1216

1317
afterEach(() => {
14-
window.fetch.mockRestore()
15-
console.error.mockRestore()
18+
fetchSpy.mockRestore()
19+
consoleErrorSpy.mockRestore()
1620
})
1721

1822
test('displays the pokemon', async () => {
@@ -34,7 +38,7 @@ test('displays the pokemon', async () => {
3438
await screen.findByRole('heading', {name: /ditto/i})
3539

3640
// verify that when props remain the same a request is not made
37-
window.fetch.mockClear()
41+
fetchSpy.mockClear()
3842

3943
userEvent.click(submit)
4044

@@ -46,7 +50,7 @@ test('displays the pokemon', async () => {
4650
)
4751

4852
// verify error handling
49-
console.error.mockImplementation(() => {})
53+
consoleErrorSpy.mockImplementation(() => {})
5054

5155
userEvent.clear(input)
5256
userEvent.type(input, 'george')
@@ -56,7 +60,7 @@ test('displays the pokemon', async () => {
5660
)
5761
expect(console.error).toHaveBeenCalledTimes(2)
5862

59-
console.error.mockReset()
63+
consoleErrorSpy.mockReset()
6064

6165
userEvent.type(input, 'mew')
6266
userEvent.click(submit)

‎src/__tests__/02.js‎ renamed to ‎src/__tests__/02.tsx‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import * as React from 'react'
22
import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
33
import {render, screen} from '@testing-library/react'
44
import userEvent from '@testing-library/user-event'
5-
import App from '../final/02'
5+
// import App from '../final/02'
6+
import App from '../final-ts/02'
67
// import App from '../exercise/02'
78

9+
let spyFetch: jest.SpyInstance
10+
let spyConsoleError: jest.SpyInstance
11+
812
beforeEach(() => {
9-
jest.spyOn(window, 'fetch')
10-
jest.spyOn(console, 'error')
13+
spyFetch=jest.spyOn(window, 'fetch')
14+
spyConsoleError=jest.spyOn(console, 'error')
1115
})
1216

1317
afterEach(() => {
14-
window.fetch.mockRestore()
15-
console.error.mockRestore()
18+
spyFetch.mockRestore()
19+
spyConsoleError.mockRestore()
1620
})
1721

1822
test('displays the pokemon', async () => {
@@ -34,7 +38,7 @@ test('displays the pokemon', async () => {
3438
await screen.findByRole('heading', {name: /ditto/i})
3539

3640
// verify that when props remain the same a request is not made
37-
window.fetch.mockClear()
41+
spyFetch.mockClear()
3842

3943
userEvent.click(submit)
4044

@@ -46,7 +50,7 @@ test('displays the pokemon', async () => {
4650
)
4751

4852
// verify error handling
49-
console.error.mockImplementation(() => {})
53+
spyConsoleError.mockImplementation(() => {})
5054

5155
userEvent.clear(input)
5256
userEvent.type(input, 'george')
@@ -56,5 +60,5 @@ test('displays the pokemon', async () => {
5660
)
5761
expect(console.error).toHaveBeenCalledTimes(2)
5862

59-
console.error.mockReset()
63+
spyConsoleError.mockReset()
6064
})

‎src/__tests__/03.extra-2.js‎ renamed to ‎src/__tests__/03.extra-2.tsx‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
33
import {render, screen} from '@testing-library/react'
44
import userEvent from '@testing-library/user-event'
55
import App from '../final/03.extra-2'
6+
// import App from '../final-ts/03.extra-2'
67
// import App from '../exercise/03.extra-2'
78

9+
let fetchSpy: jest.SpyInstance
10+
let consoleErrorSpy: jest.SpyInstance
11+
812
beforeEach(() => {
9-
jest.spyOn(window, 'fetch')
10-
jest.spyOn(console, 'error')
13+
fetchSpy=jest.spyOn(window, 'fetch')
14+
consoleErrorSpy=jest.spyOn(console, 'error')
1115
})
1216

1317
afterEach(() => {
14-
window.fetch.mockRestore()
15-
console.error.mockRestore()
18+
fetchSpy.mockRestore()
19+
consoleErrorSpy.mockRestore()
1620
})
1721

1822
test('displays the pokemon', async () => {
@@ -34,7 +38,7 @@ test('displays the pokemon', async () => {
3438
await screen.findByRole('heading', {name: /ditto/i})
3539

3640
// verify that when props remain the same a request is not made
37-
window.fetch.mockClear()
41+
fetchSpy.mockClear()
3842

3943
userEvent.click(submit)
4044

@@ -46,7 +50,7 @@ test('displays the pokemon', async () => {
4650
)
4751

4852
// verify error handling
49-
console.error.mockImplementation(() => {})
53+
consoleErrorSpy.mockImplementation(() => {})
5054

5155
userEvent.clear(input)
5256
userEvent.type(input, 'george')
@@ -56,8 +60,8 @@ test('displays the pokemon', async () => {
5660
)
5761
expect(console.error).toHaveBeenCalledTimes(2)
5862

59-
console.error.mockReset()
60-
window.fetch.mockClear()
63+
consoleErrorSpy.mockReset()
64+
fetchSpy.mockClear()
6165

6266
// use the cached value
6367
userEvent.click(screen.getByRole('button', {name: /ditto/i}))

‎src/__tests__/03.js‎ renamed to ‎src/__tests__/03.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import {render, screen} from '@testing-library/react'
33
import userEvent from '@testing-library/user-event'
44
import App from '../final/03'
5+
// import App from '../final-ts/03'
56
// import App from '../exercise/03'
67

78
test('clicking the button increments the count', () => {

‎src/__tests__/04.js‎ renamed to ‎src/__tests__/04.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import {render} from '@testing-library/react'
33
import userEvent from '@testing-library/user-event'
44
import App from '../final/04'
5+
// import App from '../final-ts/04'
56
// import App from '../exercise/04'
67

78
test('adds and removes children from the log', () => {
@@ -24,12 +25,12 @@ test('scrolls to the bottom', () => {
2425
const scrollTopSetter = jest.fn()
2526
Object.defineProperties(log, {
2627
scrollHeight: {
27-
get() {
28+
get(): number {
2829
return 100
2930
},
3031
},
3132
scrollTop: {
32-
get() {
33+
get(): number {
3334
return 0
3435
},
3536
set: scrollTopSetter,

‎src/__tests__/05.js‎ renamed to ‎src/__tests__/05.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import {render} from '@testing-library/react'
33
import userEvent from '@testing-library/user-event'
44
import App from '../final/05'
5+
// import App from '../final-ts/05'
56
// import App from '../exercise/05'
67

78
test('adds and removes children from the log', () => {

‎src/__tests__/06.js‎ renamed to ‎src/__tests__/06.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react'
33
import {alfredTip} from '@kentcdodds/react-workshop-app/test-utils'
44
import {render, act} from '@testing-library/react'
55
import App from '../final/06'
6+
// import App from '../final-ts/06'
67
// import App from '../exercise/06'
78

89
beforeAll(() => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /