11import {
22 getCleanPropName ,
33 getAbodeElements ,
4+ getRegisteredComponents ,
45 unPopulatedElements ,
56 setUnpopulatedElements ,
67 getElementProps ,
@@ -12,6 +13,8 @@ import {
1213 populate ,
1314 delay ,
1415} from '../src/abode' ;
16+ // @ts -ignore
17+ import TestComponent from './TestComponent' ;
1518
1619import 'mutationobserver-shim' ;
1720global . MutationObserver = window . MutationObserver ;
@@ -102,30 +105,56 @@ describe('exported functions', () => {
102105 register ( 'TestComponent' , ( ) => import ( './TestComponent' ) ) ;
103106 expect ( Object . keys ( components ) ) . toEqual ( [ 'TestComponent' ] ) ;
104107 expect ( Object . values ( components ) . length ) . toEqual ( 1 ) ;
105- const promise = Object . values ( components ) [ 0 ] ;
108+ let promise = Object . values ( components ) [ 0 ] ;
106109 expect ( typeof promise . then ) . toEqual ( 'function' ) ;
107- const module = await promise ;
110+ let module = await promise ;
111+ expect ( typeof module ) . toEqual ( 'object' ) ;
108112 expect ( Object . keys ( module ) ) . toEqual ( [ 'default' ] ) ;
113+
114+ register ( 'TestComponent2' , ( ) => TestComponent ) ;
115+ expect ( Object . keys ( components ) ) . toEqual ( [
116+ 'TestComponent' ,
117+ 'TestComponent2' ,
118+ ] ) ;
119+ expect ( Object . values ( components ) . length ) . toEqual ( 2 ) ;
120+ promise = Object . values ( components ) [ 1 ] ;
121+ expect ( typeof promise . then ) . toEqual ( 'function' ) ;
122+ module = await promise ;
123+ expect ( typeof module ) . toEqual ( 'function' ) ;
109124 } ) ;
110125
111126 it ( 'populate' , async ( ) => {
112127 const abodeElement = document . createElement ( 'div' ) ;
113128 abodeElement . setAttribute ( 'data-component' , 'TestComponent' ) ;
129+ const abodeSecondElement = document . createElement ( 'div' ) ;
130+ abodeSecondElement . setAttribute ( 'data-component' , 'TestComponent2' ) ;
114131 document . body . appendChild ( abodeElement ) ;
132+ document . body . appendChild ( abodeSecondElement ) ;
115133 expect ( document . body . innerHTML ) . toEqual (
116- `<div data-component="TestComponent"></div>`
134+ `<div data-component="TestComponent"></div><div data-component="TestComponent2"></div> `
117135 ) ;
118136
119137 register ( 'TestComponent' , ( ) => import ( './TestComponent' ) ) ;
120- populate ( ) ;
138+ register ( 'TestComponent2' , ( ) => TestComponent ) ;
139+ await populate ( ) ;
121140
122141 await delay ( 20 ) ;
123142
124143 expect ( document . body . innerHTML ) . toEqual (
125- `<div data-component="TestComponent" react-abode-populated="true"><div>testing 1 2 3 </div></div>`
144+ `<div data-component="TestComponent" react-abode-populated="true"><div>testing 1 2 3 </div></div>` +
145+ `<div data-component="TestComponent2" react-abode-populated="true"><div>testing 1 2 3 </div></div>`
126146 ) ;
127147 } ) ;
128148
149+ it ( 'getRegisteredComponents' , ( ) => {
150+ register ( 'TestComponent' , ( ) => import ( './TestComponent' ) ) ;
151+ register ( 'TestComponent2' , ( ) => TestComponent ) ;
152+
153+ const registeredComponents = getRegisteredComponents ( ) ;
154+
155+ expect ( Object . keys ( registeredComponents ) . length ) . toEqual ( 2 ) ;
156+ } ) ;
157+
129158 it . skip ( 'getActiveComponents' , ( ) => { } ) ;
130159 it . skip ( 'setComponentSelector' , ( ) => { } ) ;
131160 it . skip ( 'register' , ( ) => { } ) ;
0 commit comments