File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,39 @@ 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+ function wrapH ( h ) {
95+ return function ( type , props , ...children ) {
96+ if ( type === '@static' ) {
97+ this [ 0 ] &= ~ 3 ;
98+ return children ;
99+ }
100+ if ( props [ '@static' ] ) {
101+ this [ 0 ] &= ~ 3 ;
102+ }
103+ return h ( type , props , ...children ) ;
104+ } ;
105+ }
106+
107+ test ( 'should be able to force subtrees to be static via a prop' , ( ) => {
108+ const html = htm . bind ( wrapH ( h ) ) ;
109+ const x = ( ) => html `< div @static > ${ 'a' } </ div > ` ;
110+ const a = x ( ) ;
111+ const b = x ( ) ;
112+ expect ( a ) . toEqual ( { tag : 'div' , props : { '@static' : true } , children : [ 'a' ] } ) ;
113+ expect ( b ) . toEqual ( { tag : 'div' , props : { '@static' : true } , children : [ 'a' ] } ) ;
114+ expect ( a ) . toBe ( b ) ;
115+ } ) ;
116+
117+ test ( 'should be able to force subtrees to be static via a special tag' , ( ) => {
118+ const html = htm . bind ( wrapH ( h ) ) ;
119+ const x = ( ) => html `< @static> ${ 'a' } </ /> ` ;
120+ const a = x ( ) ;
121+ const b = x ( ) ;
122+ expect ( a ) . toEqual ( [ 'a' ] ) ;
123+ expect ( b ) . toEqual ( [ 'a' ] ) ;
124+ expect ( a ) . toBe ( b ) ;
125+ } ) ;
126+ } ) ;
92127} ) ;
You can’t perform that action at this time.
0 commit comments