44 compileVue ,
55 compileWithDeps ,
66 createInstance ,
7+ addTaskHook ,
8+ resetTaskHook ,
79 getRoot ,
810 getEvents ,
911 fireEvent
@@ -19,6 +21,7 @@ function createRenderTestCase (name) {
1921 const instance = createInstance ( id , code )
2022 setTimeout ( ( ) => {
2123 expect ( getRoot ( instance ) ) . toEqual ( target )
24+ instance . $destroy ( )
2225 done ( )
2326 } , 50 )
2427 } ) . catch ( done . fail )
@@ -40,6 +43,7 @@ function createEventTestCase (name) {
4043 fireEvent ( instance , event . ref , event . type , { } )
4144 setTimeout ( ( ) => {
4245 expect ( getRoot ( instance ) ) . toEqual ( after )
46+ instance . $destroy ( )
4347 done ( )
4448 } , 50 )
4549 } , 50 )
@@ -79,6 +83,7 @@ describe('Usage', () => {
7983 setTimeout ( ( ) => {
8084 const target = readObject ( 'recycle-list/components/stateless.vdom.js' )
8185 expect ( getRoot ( instance ) ) . toEqual ( target )
86+ instance . $destroy ( )
8287 done ( )
8388 } , 50 )
8489 } ) . catch ( done . fail )
@@ -94,29 +99,89 @@ describe('Usage', () => {
9499 setTimeout ( ( ) => {
95100 const target = readObject ( 'recycle-list/components/stateless-with-props.vdom.js' )
96101 expect ( getRoot ( instance ) ) . toEqual ( target )
102+ instance . $destroy ( )
103+ done ( )
104+ } , 50 )
105+ } ) . catch ( done . fail )
106+ } )
107+
108+ it ( 'multi stateless components' , done => {
109+ compileWithDeps ( 'recycle-list/components/stateless-multi-components.vue' , [ {
110+ name : 'banner' ,
111+ path : 'recycle-list/components/banner.vue'
112+ } , {
113+ name : 'poster' ,
114+ path : 'recycle-list/components/poster.vue'
115+ } , {
116+ name : 'footer' ,
117+ path : 'recycle-list/components/footer.vue'
118+ } ] ) . then ( code => {
119+ const id = String ( Date . now ( ) * Math . random ( ) )
120+ const instance = createInstance ( id , code )
121+ setTimeout ( ( ) => {
122+ const target = readObject ( 'recycle-list/components/stateless-multi-components.vdom.js' )
123+ expect ( getRoot ( instance ) ) . toEqual ( target )
124+ instance . $destroy ( )
97125 done ( )
98126 } , 50 )
99127 } ) . catch ( done . fail )
100128 } )
101129
102130 it ( 'stateful component' , done => {
131+ const tasks = [ ]
132+ addTaskHook ( ( _ , task ) => tasks . push ( task ) )
103133 compileWithDeps ( 'recycle-list/components/stateful.vue' , [ {
104134 name : 'counter' ,
105135 path : 'recycle-list/components/counter.vue'
106136 } ] ) . then ( code => {
107137 const id = String ( Date . now ( ) * Math . random ( ) )
108138 const instance = createInstance ( id , code )
139+ expect ( tasks . length ) . toEqual ( 7 )
140+ tasks . length = 0
141+ instance . $triggerHook ( 2 , 'create' , [ 'component-1' ] )
142+ instance . $triggerHook ( 2 , 'create' , [ 'component-2' ] )
143+ instance . $triggerHook ( 'component-1' , 'attach' )
144+ instance . $triggerHook ( 'component-2' , 'attach' )
145+ expect ( tasks . length ) . toEqual ( 2 )
146+ expect ( tasks [ 0 ] . method ) . toEqual ( 'updateComponentData' )
147+ // expect(tasks[0].args).toEqual([{ count: 42 }])
148+ expect ( tasks [ 1 ] . method ) . toEqual ( 'updateComponentData' )
149+ // expect(tasks[1].args).toEqual([{ count: 42 }])
109150 setTimeout ( ( ) => {
110151 const target = readObject ( 'recycle-list/components/stateful.vdom.js' )
111152 expect ( getRoot ( instance ) ) . toEqual ( target )
112153 const event = getEvents ( instance ) [ 0 ]
154+ tasks . length = 0
113155 fireEvent ( instance , event . ref , event . type , { } )
114156 setTimeout ( ( ) => {
115- expect ( getRoot ( instance ) ) . toEqual ( target )
157+ // expect(tasks.length).toEqual(1)
158+ // expect(tasks[0]).toEqual({
159+ // module: 'dom',
160+ // method: 'updateComponentData',
161+ // args: [{ count: 43 }]
162+ // })
163+ instance . $destroy ( )
164+ resetTaskHook ( )
116165 done ( )
117166 } )
118167 } , 50 )
119168 } ) . catch ( done . fail )
120169 } )
170+
171+ it ( 'stateful component with v-model' , done => {
172+ compileWithDeps ( 'recycle-list/components/stateful-v-model.vue' , [ {
173+ name : 'editor' ,
174+ path : 'recycle-list/components/editor.vue'
175+ } ] ) . then ( code => {
176+ const id = String ( Date . now ( ) * Math . random ( ) )
177+ const instance = createInstance ( id , code )
178+ setTimeout ( ( ) => {
179+ const target = readObject ( 'recycle-list/components/stateful-v-model.vdom.js' )
180+ expect ( getRoot ( instance ) ) . toEqual ( target )
181+ instance . $destroy ( )
182+ done ( )
183+ } , 50 )
184+ } ) . catch ( done . fail )
185+ } )
121186 } )
122187} )
0 commit comments