1+ import '@theuiteam/lib-builder/configs/setupEnzyme' ;
2+ import { mount } from 'enzyme' ;
13import * as React from 'react' ;
2- import { mount } from 'enzyme' ;
4+
5+ import { ImportedComponent } from '../src/Component' ;
36import loader from '../src/HOC' ;
4- import { ImportedComponent } from '../src/Component' ;
5- import { toLoadable } from '../src/loadable' ;
7+ import { toLoadable } from '../src/loadable' ;
68
79describe ( 'Async Component' , ( ) => {
8-
910 describe ( 'loader' , ( ) => {
10- it ( 'should load component' , ( done ) => {
11- const TargetComponent = ( { payload} : any ) => < div > { payload } </ div > ;
12- const Component = loader ( ( ) => TargetComponent ) ;
11+ it ( 'should load component' , done => {
12+ const TargetComponent = ( { payload } : any ) => < div > { payload } </ div > ;
13+ const Component = loader ( ( ) => Promise . resolve ( TargetComponent ) ) ;
1314
14- const wrapper = mount ( < Component payload = { 42 } /> ) ;
15+ const wrapper = mount ( < Component payload = { 42 } /> ) ;
1516
16- expect ( wrapper . find ( TargetComponent ) ) . toHaveLength ( 0 )
17+ expect ( wrapper . find ( TargetComponent ) ) . toHaveLength ( 0 ) ;
1718 setImmediate ( ( ) => {
1819 wrapper . update ( ) ;
19- expect ( wrapper . find ( TargetComponent ) . html ( ) ) . toContain ( "42" ) ;
20+ expect ( wrapper . find ( TargetComponent ) . html ( ) ) . toContain ( '42' ) ;
2021 wrapper . unmount ( ) ;
2122 done ( ) ;
2223 } ) ;
2324 } ) ;
2425
25- it ( 'forwardRef' , ( done ) => {
26- const TargetComponent = React . forwardRef < any , any > ( ( { payload} , ref ) => < div ref = { ref } > { payload } </ div > ) ;
27- const Component = loader ( ( ) => TargetComponent ) ;
26+ it ( 'forwardRef' , done => {
27+ const TargetComponent = React . forwardRef < any , any > ( ( { payload } , fref ) => < div ref = { fref } > { payload } </ div > ) ;
28+ const Component = loader ( ( ) => Promise . resolve ( TargetComponent ) ) ;
2829 const ref = React . createRef ( ) ;
29- mount ( < Component payload = { 42 } ref = { ref } /> ) ;
30+ mount ( < Component payload = { 42 } ref = { ref } /> ) ;
3031
3132 setImmediate ( ( ) => {
3233 expect ( ref . current ) . not . toBe ( null ) ;
@@ -35,23 +36,18 @@ describe('Async Component', () => {
3536 } ) ;
3637 } ) ;
3738
38- describe ( "SSR" , ( ) => {
39-
39+ describe ( 'SSR' , ( ) => {
4040 it ( 'should precache Components' , async ( ) => {
41- const TargetComponent = ( { payload} ) => < div > { payload } </ div > ;
41+ const TargetComponent = ( { payload } : any ) => < div > { payload } </ div > ;
4242 const LoadingComponent = ( ) => < div > loading</ div > ;
43- const loader = toLoadable ( ( ) => Promise . resolve ( TargetComponent ) ) ;
44- await loader . load ( ) ;
43+ const loadable = toLoadable ( ( ) => Promise . resolve ( TargetComponent ) ) ;
44+ await loadable . load ( ) ;
4545
4646 const wrapper = mount (
47- < ImportedComponent
48- loadable = { loader }
49- LoadingComponent = { LoadingComponent }
50- forwardProps = { { payload : 42 } }
51- />
47+ < ImportedComponent loadable = { loadable } LoadingComponent = { LoadingComponent } forwardProps = { { payload : 42 } } />
5248 ) ;
5349 expect ( wrapper . find ( LoadingComponent ) ) . toHaveLength ( 0 ) ;
5450 expect ( wrapper . find ( TargetComponent ) . html ( ) ) . toContain ( '42' ) ;
5551 } ) ;
5652 } ) ;
57- } ) ;
53+ } ) ;
0 commit comments