@@ -15,26 +15,27 @@ beforeEach(() => {
1515afterEach ( ( ) => {
1616 host . remove ( )
1717} )
18-
18+ const createDemo = ( defaultValue : boolean ) =>
19+ defineComponent ( {
20+ setup ( ) {
21+ const visible = ref ( defaultValue )
22+ function handleClick ( ) {
23+ visible . value = ! visible . value
24+ }
25+ const t0 = template ( '<button>toggle</button><h1>hello world</h1>' )
26+ const n0 = t0 ( )
27+ const {
28+ 0 : [ n1 ] ,
29+ 1 : [ n2 ] ,
30+ } = children ( n0 )
31+ withDirectives ( n2 , [ [ vShow , ( ) => visible . value ] ] )
32+ on ( n1 as HTMLElement , 'click' , handleClick )
33+ return n0
34+ } ,
35+ } )
1936describe ( 'directive: v-show' , ( ) => {
2037 test ( 'basic' , async ( ) => {
21- const demo = defineComponent ( {
22- setup ( ) {
23- const visible = ref ( true )
24- function handleClick ( ) {
25- visible . value = ! visible . value
26- }
27- const t0 = template ( '<button>toggle</button><h1>hello world</h1>' )
28- const n0 = t0 ( )
29- const {
30- 0 : [ n1 ] ,
31- 1 : [ n2 ] ,
32- } = children ( n0 )
33- withDirectives ( n2 , [ [ vShow , ( ) => visible . value ] ] )
34- on ( n1 as HTMLElement , 'click' , ( ...args ) => handleClick ( ...args ) )
35- return n0
36- } ,
37- } )
38+ const demo = createDemo ( true )
3839 render ( demo as any , { } , '#host' )
3940 const btn = host . querySelector ( 'button' )
4041 expect ( host . innerHTML ) . toBe ( '<button>toggle</button><h1>hello world</h1>' )
@@ -44,4 +45,14 @@ describe('directive: v-show', () => {
4445 '<button>toggle</button><h1 style="display: none;">hello world</h1>' ,
4546 )
4647 } )
48+ test ( 'should hide content when default value is false' , async ( ) => {
49+ const demo = createDemo ( false )
50+ render ( demo as any , { } , '#host' )
51+ const btn = host . querySelector ( 'button' )
52+ const h1 = host . querySelector ( 'h1' )
53+ expect ( h1 ?. style . display ) . toBe ( 'none' )
54+ btn ?. click ( )
55+ await nextTick ( )
56+ expect ( h1 ?. style . display ) . toBe ( '' )
57+ } )
4758} )
0 commit comments