@@ -22,21 +22,7 @@ const toCmd = (msg: string) => Task.perform(Task.succeed(0), () => msg);
2222
2323describe ( 'Test Program' , ( ) => {
2424
25- it ( 'first' , ( ) => {
26- const props : ProgramProps < number , string > = {
27- init : init1 ,
28- view : view1 ,
29- update : update1 ,
30- subscriptions : ( ) => Sub . none < string > ( )
31- }
32- return mountWhenIdle ( props ) . then ( ( [ model , wrapper ] ) => {
33- expect ( model ) . toEqual ( 6 )
34- // expect(wrapper).toHaveHTML('')
35- expect ( wrapper . find ( '.count' ) ) . toHaveText ( '6' )
36- } )
37- } )
38-
39- it ( 'updateUntilIdle' , ( ) => {
25+ it ( 'expect when program is idle' , ( ) => {
4026 const props : ProgramProps < number , string > = {
4127 init : init1 ,
4228 view : view1 ,
@@ -50,65 +36,3 @@ describe('Test Program', () => {
5036 } )
5137 } )
5238} )
53-
54- function mountWhenIdle < Model , Msg > ( props : ProgramProps < Model , Msg > ) {
55- const testable = new Testable ( props ) ;
56- // return Promise.resolve(mount(<Program {...testable.programProps} />));
57- return testable . mountWhenIdle ( )
58- }
59-
60-
61- class Testable < Model , Msg > {
62- private resolve ?: ( idle : [ Model , ReactWrapper < Program < Model , Msg > , ProgramProps < Model , Msg > , never > ] ) => void ;
63- private cmds : Cmd < Msg > [ ] = [ ] ;
64- private dispatch ?: Dispatcher < Msg > ;
65- private model ?: Model ;
66- private viewed ?: ReactNode ;
67-
68- constructor ( private readonly props : ProgramProps < Model , Msg > ) {
69- }
70-
71- get programProps ( ) {
72- const props : ProgramProps < Model , Msg > = {
73- init : this . props . init ,
74- view : ( dispatch : Dispatcher < Msg > , model : Model ) => this . view ( dispatch , model ) ,
75- update : ( msg : Msg , model : Model ) => this . update ( msg , model ) ,
76- subscriptions : this . props . subscriptions
77- }
78- return props
79- }
80-
81- private view ( dispatch : Dispatcher < Msg > , model : Model ) {
82- this . dispatch = dispatch ;
83- this . viewed = this . props . view ( dispatch , model ) ;
84- return this . viewed ;
85- }
86-
87- private update ( msg : Msg , model : Model ) : [ Model , Cmd < Msg > ] {
88- const [ model1 , cmd1 ] = this . props . update ( msg , model ) ;
89- this . model = model1 ;
90- this . cmds . push ( cmd1 ) ;
91- setTimeout ( ( ) => {
92- this . process ( ) ;
93- } , 0 ) ;
94- return [ model1 , Cmd . none ( ) ] ;
95- }
96-
97- private process ( ) {
98- this . cmds = this . cmds . filter ( cmd => cmd . constructor . name !== 'CmdNone' )
99- if ( this . cmds . length === 0 ) {
100- this . resolve ?.( [ this . model ! , mount ( < > { this . viewed } </ > ) ] ) ;
101- return ;
102- }
103- const first = this . cmds [ 0 ]
104- this . cmds = this . cmds . slice ( 1 )
105- first . execute ( this . dispatch ! )
106- }
107-
108- mountWhenIdle ( ) : Promise < [ Model , ReactWrapper < Program < Model , Msg > , ProgramProps < Model , Msg > , never > ] > {
109- mount ( < Program { ...this . programProps } /> )
110- return new Promise ( resolve => {
111- this . resolve = resolve ;
112- } ) ;
113- }
114- }
0 commit comments