forked from TechBowl-japan/react-stations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstation10.test.tsx
43 lines (36 loc) · 1.3 KB
/
station10.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
import React from 'react'
import renderer, { act } from 'react-test-renderer'
import { breeds as nestedBreeds, fetchMock } from './mock/fetch'
import { createAsync } from './utils/createAsync'
const breeds = Object.keys(nestedBreeds)
describe('<BreedsSelect />', () => {
const fetch = jest.fn()
window.fetch = fetch
fetch.mockImplementation(fetchMock)
it('exists', async () => {
const { BreedsSelect } = require('../src/BreedsSelect')
expect(BreedsSelect).toBeTruthy()
await act(async () => {
renderer.create(<BreedsSelect breeds={breeds} />)
})
})
it('has `<select>` and `<option>` tags', async () => {
const { BreedsSelect } = require('../src/BreedsSelect')
const res = await createAsync(<BreedsSelect breeds={breeds} />)
expect(res.root.findAllByType('select').length).not.toBe(0)
expect(res.root.findAllByType('option').length).not.toBe(0)
})
})
describe('<App />', () => {
it('value changes when `onChange` wes called', async () => {
const { App } = require('../src/App')
const res = await createAsync(<App />)
const selectTag = res.root.findByType('select')!
const value = 'test'
expect(selectTag).toBeTruthy()
act(() => {
selectTag.props.onChange({ target: { value } })
})
expect(selectTag.props.value).toBe(value)
})
})