|
1 | | -import { mount, ReactWrapper } from 'enzyme'; |
2 | | -import { extendJest, Cmd, Sub, Task, Program, ProgramProps, updateUntilIdle } from "react-tea-cup"; |
3 | | -import React, { ReactNode } from 'react'; |
4 | | -import { Dispatcher } from 'tea-cup-core'; |
| 1 | +import { mount } from 'enzyme'; |
| 2 | +import { Cmd, Dispatcher, Sub, Task } from 'tea-cup-core'; |
| 3 | +import { extendJest, ProgramProps, updateUntilIdle } from 'react-tea-cup'; |
| 4 | +import React from 'react'; |
5 | 5 |
|
6 | 6 | extendJest(expect); |
7 | 7 |
|
8 | 8 | const init1: () => [number, Cmd<string>] = () => { |
9 | | - return [0, toCmd('go')]; |
10 | | -} |
| 9 | + return [0, toCmd('go')]; |
| 10 | +}; |
11 | 11 |
|
12 | | -const view1: (dispatch: Dispatcher<string>, model: number) => React.ReactNode = (dispatch: Dispatcher<string>, model: number) => { |
13 | | - return (<div className={'count'}>{model}</div>); |
14 | | -} |
| 12 | +const view1: (dispatch: Dispatcher<string>, model: number) => React.ReactNode = ( |
| 13 | + dispatch: Dispatcher<string>, |
| 14 | + model: number, |
| 15 | +) => { |
| 16 | + return <div className={'count'}>{model}</div>; |
| 17 | +}; |
15 | 18 |
|
16 | 19 | const update1: (msg: string, model: number) => [number, Cmd<string>] = (msg: string, model: number) => { |
17 | | - return [model + 1, model < 5 ? toCmd('go') : Cmd.none()]; |
18 | | -} |
| 20 | + return [model + 1, model < 5 ? toCmd('go') : Cmd.none()]; |
| 21 | +}; |
19 | 22 |
|
20 | 23 | // const toCmd = (msg: string) => Task.perform(Time.in(0), () => msg); |
21 | 24 | const toCmd = (msg: string) => Task.perform(Task.succeed(0), () => msg); |
22 | 25 |
|
23 | 26 | describe('Test Program', () => { |
24 | | - |
25 | | - it('expect when program is idle', () => { |
26 | | - const props: ProgramProps<number, string> = { |
27 | | - init: init1, |
28 | | - view: view1, |
29 | | - update: update1, |
30 | | - subscriptions: () => Sub.none<string>() |
31 | | - } |
32 | | - return updateUntilIdle(props, mount).then(([model, wrapper]) => { |
33 | | - expect(model).toEqual(6) |
34 | | - // expect(wrapper).toHaveHTML('') |
35 | | - expect(wrapper.find('.count')).toHaveText('6') |
36 | | - }) |
37 | | - }) |
38 | | -}) |
| 27 | + it('expect when program is idle', () => { |
| 28 | + const props: ProgramProps<number, string> = { |
| 29 | + init: init1, |
| 30 | + view: view1, |
| 31 | + update: update1, |
| 32 | + subscriptions: () => Sub.none<string>(), |
| 33 | + }; |
| 34 | + return updateUntilIdle(props, mount).then(([model, wrapper]) => { |
| 35 | + expect(model).toEqual(6); |
| 36 | + // expect(wrapper).toHaveHTML('') |
| 37 | + expect(wrapper.find('.count')).toHaveText('6'); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
0 commit comments