forked from TechBowl-japan/react-stations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for Station No. 9; consistency for all tests
- Loading branch information
Showing
9 changed files
with
184 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import * as React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import renderer, { act } from 'react-test-renderer' | ||
import { App } from '../src/App' | ||
import { fetchMock } from './mock/fetch' | ||
|
||
it('Can create <App />', () => { | ||
renderer.create( | ||
<App />, | ||
) | ||
describe('Station No.1', () => { | ||
const fetch = jest.fn() | ||
window.fetch = fetch | ||
fetch.mockImplementation(fetchMock) | ||
|
||
it('Can create <App />', async () => { | ||
await act(async () => { | ||
renderer.create(<App />) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
import * as React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import renderer, { act, ReactTestRenderer } from 'react-test-renderer' | ||
import { App } from '../src/App' | ||
import { fetchMock } from './mock/fetch' | ||
import { createAsync } from './utils/createAsync' | ||
|
||
it('<App /> has a <header>', () => { | ||
const res = renderer.create( | ||
<App />, | ||
) | ||
|
||
res.root.findByType('header') | ||
describe('Station No.2', () => { | ||
const fetch = jest.fn() | ||
window.fetch = fetch | ||
fetch.mockImplementation(fetchMock) | ||
|
||
it('Can create <App />', async () => { | ||
await act(async () => { | ||
renderer.create(<App />) | ||
}) | ||
}) | ||
|
||
it('<App /> has a <header>', async () => { | ||
const res = await createAsync(<App />) | ||
res.root.findByType('header') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,51 @@ | ||
import * as React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import { App } from '../src/App' | ||
|
||
it('<App /> has a <header>', () => { | ||
const res = renderer.create( | ||
<App />, | ||
) | ||
|
||
res.root.findByType('header') | ||
}) | ||
|
||
it('<App /> contains a text node', () => { | ||
const res = renderer.create(<App />) | ||
|
||
let hasChildTextNode = false | ||
let stack = [...res.root.children] | ||
|
||
// run a depth-first search for a text node | ||
while (stack.length !== 0 && !hasChildTextNode) { | ||
const child = stack.pop() | ||
if (child === undefined) { | ||
throw new Error('unreachable code') | ||
import { fetchMock } from './mock/fetch' | ||
import { createAsync } from './utils/createAsync' | ||
|
||
describe('Station No.3', () => { | ||
const fetch = jest.fn() | ||
window.fetch = fetch | ||
fetch.mockImplementation(fetchMock) | ||
|
||
it('<App /> has a <header>', async () => { | ||
const res = await createAsync(<App />) | ||
res.root.findByType('header') | ||
}) | ||
|
||
it('<App /> contains a text node', async () => { | ||
const res = await createAsync(<App />) | ||
|
||
let hasChildTextNode = false | ||
let stack = [...res.root.children] | ||
|
||
// run a depth-first search for a text node | ||
while (stack.length !== 0 && !hasChildTextNode) { | ||
const child = stack.pop() | ||
if (child === undefined) { | ||
throw new Error('unreachable code') | ||
} | ||
|
||
if ((hasChildTextNode = typeof child === 'string')) { | ||
break | ||
} | ||
|
||
const children = child.children | ||
if (children.length === 0) { | ||
continue | ||
} | ||
|
||
stack = [...children, ...stack] | ||
} | ||
|
||
if ((hasChildTextNode = typeof child === 'string')) { | ||
break | ||
} | ||
|
||
const children = child.children | ||
if (children.length === 0) { | ||
continue | ||
} | ||
|
||
stack = [...children, ...stack] | ||
} | ||
|
||
expect(hasChildTextNode).toBe(true) | ||
}) | ||
expect(hasChildTextNode).toBe(true) | ||
}) | ||
|
||
it('<App /> has a <img> with src', () => { | ||
const res = renderer.create(<App />) | ||
it('<App /> has a <img> with src', async () => { | ||
const res = await createAsync(<App />) | ||
|
||
const img = res.root.findByType('img') | ||
expect(img.props.src).toBeTruthy() | ||
const img = res.root.findByType('img') | ||
expect(img.props.src).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import renderer, { act } from 'react-test-renderer' | ||
import { RandomDogButton } from '../src/RandomDogButton' | ||
import { imageUrl, fetchMock } from './mock/fetch' | ||
|
||
describe('<App />', () => { | ||
const useEffectSpy = jest.spyOn(React, 'useEffect') | ||
|
||
it('<RandomDogButton /> calls React.useEffect', () => { | ||
renderer.create(<RandomDogButton />) | ||
expect(useEffectSpy).toBeCalled() | ||
}) | ||
}) |
Oops, something went wrong.