forked from TechBowl-japan/react-stations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstation03.test.tsx
51 lines (39 loc) · 1.26 KB
/
station03.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as React from 'react'
import { fetchMock } from './mock/fetch'
import { createAsync } from './utils/createAsync'
const { App } = require('../src/App') as { App: React.ComponentType<{}> }
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]
}
expect(hasChildTextNode).toBe(true)
})
it('<App /> has a <img> with src', async () => {
const res = await createAsync(<App />)
const img = res.root.findByType('img')
expect(img.props.src).toBeTruthy()
})
})