@@ -3,18 +3,19 @@ import { describe, test, expect, vi } from 'vitest'
33import customPropertyPlugin from '../customProperty'
44
55describe ( 'customPropertyPlugin' , ( ) => {
6- const mockContext = {
6+ const context = {
77 mergeStyle : ( target : any , source : any ) => Object . assign ( target , source ) ,
88 createNode : vi . fn ( ) ,
9- props : { } ,
10- }
9+ props : { style : { } } ,
10+ devMode : false ,
11+ } as const
1112
1213 test ( 'resolves custom properties to style objects' , ( ) => {
1314 const plugin = customPropertyPlugin ( {
1415 size : ( value : number ) => ( { width : value , height : value } ) ,
1516 } )
1617
17- const result = plugin ( { size : 100 } as any , mockContext as any )
18+ const result = plugin ( { size : 100 } , context )
1819
1920 expect ( result . width ) . toBe ( 100 )
2021 expect ( result . height ) . toBe ( 100 )
@@ -25,9 +26,9 @@ describe('customPropertyPlugin', () => {
2526 spacing : ( value : number ) => ( { padding : value , margin : value } ) ,
2627 } )
2728
28- const result = plugin ( { spacing : 10 } as any , mockContext as any )
29+ const result = plugin ( { spacing : 10 } , context )
2930
30- expect ( result . spacing ) . toBeUndefined ( )
31+ expect ( ' spacing' in result ) . toBeFalsy ( )
3132 expect ( result . padding ) . toBe ( 10 )
3233 expect ( result . margin ) . toBe ( 10 )
3334 } )
@@ -37,7 +38,7 @@ describe('customPropertyPlugin', () => {
3738 padding : ( value : number ) => ( { padding : value * 2 } ) ,
3839 } )
3940
40- const result = plugin ( { padding : 10 } as any , mockContext as any )
41+ const result = plugin ( { padding : 10 } , context )
4142
4243 expect ( result . padding ) . toBe ( 20 )
4344 } )
@@ -50,23 +51,20 @@ describe('customPropertyPlugin', () => {
5051 const result = plugin (
5152 {
5253 ':hover' : { size : 50 } ,
53- } as any ,
54- mockContext as any
54+ } ,
55+ context
5556 )
5657
57- expect ( result [ ':hover' ] . width ) . toBe ( 50 )
58- expect ( result [ ':hover' ] . height ) . toBe ( 50 )
58+ expect ( result [ ':hover' ] ? .width ) . toBe ( 50 )
59+ expect ( result [ ':hover' ] ? .height ) . toBe ( 50 )
5960 } )
6061
6162 test ( 'passes through non-custom properties' , ( ) => {
6263 const plugin = customPropertyPlugin ( {
6364 size : ( value : number ) => ( { width : value } ) ,
6465 } )
6566
66- const result = plugin (
67- { size : 100 , color : 'red' } as any ,
68- mockContext as any
69- )
67+ const result = plugin ( { size : 100 , color : 'red' } , context )
7068
7169 expect ( result . color ) . toBe ( 'red' )
7270 expect ( result . width ) . toBe ( 100 )
@@ -78,11 +76,10 @@ describe('customPropertyPlugin', () => {
7876 spacing : ( value : number ) => ( { padding : value } ) ,
7977 } )
8078
81- const result = plugin ( { size : 100 , spacing : 10 } as any , mockContext as any )
79+ const result = plugin ( { size : 100 , spacing : 10 } , context )
8280
8381 expect ( result . width ) . toBe ( 100 )
8482 expect ( result . height ) . toBe ( 100 )
8583 expect ( result . padding ) . toBe ( 10 )
8684 } )
8785} )
88-
0 commit comments