File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,25 @@ describe('htm', () => {
8989 expect ( html `< div x =${ 1 } > < a y =${ 2 } / > < b /> </ div > ` ) . toBe ( 3 ) ;
9090 } ) ;
9191 } ) ;
92+
93+ describe ( 'the h function should be able to modify `this[0]`' , ( ) => {
94+ test ( 'should be able to force subtrees to be static' , ( ) => {
95+ function wrapH ( h ) {
96+ return function ( type , props , ...children ) {
97+ if ( props [ '@static' ] ) {
98+ this [ 0 ] &= ~ 3 ;
99+ }
100+ return h ( type , props , ...children ) ;
101+ } ;
102+ }
103+
104+ const html = htm . bind ( wrapH ( h ) ) ;
105+ const x = ( ) => html `< div @static > ${ 'a' } </ div > ` ;
106+ const a = x ( ) ;
107+ const b = x ( ) ;
108+ expect ( a ) . toEqual ( { tag : 'div' , props : { '@static' : true } , children : [ 'a' ] } ) ;
109+ expect ( b ) . toEqual ( { tag : 'div' , props : { '@static' : true } , children : [ 'a' ] } ) ;
110+ expect ( a ) . toBe ( b ) ;
111+ } ) ;
112+ } ) ;
92113} ) ;
You can’t perform that action at this time.
0 commit comments