forked from TechBowl-japan/react-stations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstation03.test.tsx
57 lines (44 loc) · 1.46 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
52
53
54
55
56
57
import { describe, expect, it, vi } from 'vitest'
import * as React from 'react'
import { fetchMock } from './mock/fetch'
import { render, waitFor } from '@testing-library/react'
const { App } = (await import('../src/App')) as { App: React.ComponentType<{}> }
describe('Station No.3', () => {
const fetch = vi.fn()
window.fetch = fetch
fetch.mockImplementation(fetchMock)
it('<App /> has a <header>', async () => {
const res = await render(<App />)
const header = res.container.querySelector('header')
await waitFor(() => {
expect(header).not.toBeNull()
})
})
it('<App /> contains a text node', async () => {
const res = await render(<App />)
let hasChildTextNode = false
let stack = Array.from(res.container.childNodes)
// 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 = child instanceof Text)) {
break
}
const children = child.childNodes
if (children.length === 0) {
continue
}
stack = [...Array.from(children), ...stack]
}
expect(hasChildTextNode).toBe(true)
})
it('<App /> has a <img> with src', async () => {
const res = await render(<App />)
const img = res.container.querySelector('img')
expect(img).not.toBeNull()
expect(img!.src).toBeTruthy()
})
})