@@ -4,7 +4,10 @@ import { createCache, StyleProvider } from '@ant-design/cssinjs';
44import { genStyleUtils } from '../src' ;
55
66interface TestTokenMap {
7- TestComponent : Record < string , any > ;
7+ TestComponent : {
8+ colorPrimary ?: string ;
9+ fontSize ?: number ;
10+ } ;
811}
912
1013describe ( 'extraCssVarPrefixCls' , ( ) => {
@@ -17,9 +20,23 @@ describe('extraCssVarPrefixCls', () => {
1720 theme : {
1821 id : 'test' ,
1922 } as any ,
20- realToken : { colorPrimary : '#1890ff' , fontSize : 14 } ,
23+ realToken : {
24+ colorPrimary : '#1890ff' ,
25+ fontSize : 14 ,
26+ TestComponent : {
27+ colorPrimary : '#ff0000' ,
28+ fontSize : 16 ,
29+ } ,
30+ } ,
2131 hashId : 'css-dev-only-do-not-override-abc123' ,
22- token : { colorPrimary : '#1890ff' , fontSize : 14 } ,
32+ token : {
33+ colorPrimary : '#1890ff' ,
34+ fontSize : 14 ,
35+ TestComponent : {
36+ colorPrimary : '#ff0000' ,
37+ fontSize : 16 ,
38+ } ,
39+ } ,
2340 cssVar : {
2441 prefix : 'ant' ,
2542 key : 'test' ,
@@ -28,7 +45,7 @@ describe('extraCssVarPrefixCls', () => {
2845 useCSP : ( ) => ( { nonce : 'nonce' } ) ,
2946 getResetStyles : ( ) => [ ] ,
3047 layer : {
31- name : 'test ' ,
48+ name : 'mock-layer ' ,
3249 dependencies : [ 'parent' ] ,
3350 } ,
3451 } ;
@@ -42,17 +59,25 @@ describe('extraCssVarPrefixCls', () => {
4259 it ( 'should inject CSS vars for extraCssVarPrefixCls' , ( ) => {
4360 const hooks = genStyleHooks (
4461 'TestComponent' ,
45- ( ) => ( { } ) ,
46- ( ) => ( { } ) ,
62+ ( token ) => ( {
63+ [ `${ token . componentCls } ` ] : {
64+ color : token . colorPrimary ,
65+ fontSize : token . fontSize ,
66+ } ,
67+ } ) ,
68+ ( ) => ( {
69+ colorPrimary : '#ff0000' ,
70+ fontSize : 16 ,
71+ } ) ,
4772 {
4873 extraCssVarPrefixCls : [ 'custom-a' , 'custom-b' ] ,
49- injectStyle : true ,
5074 } ,
5175 ) ;
5276
5377 const TestComponent = ( ) => {
54- const [ hashId ] = hooks ( 'test-prefix' ) ;
55- return < div > { hashId } </ div > ;
78+ const [ hashId , cssVarCls ] = hooks ( 'test-prefix' ) ;
79+ const className = [ hashId , cssVarCls ] . filter ( Boolean ) . join ( ' ' ) ;
80+ return < div className = { className } > { hashId } </ div > ;
5681 } ;
5782
5883 render (
@@ -65,9 +90,8 @@ describe('extraCssVarPrefixCls', () => {
6590 . map ( ( el ) => el . textContent )
6691 . join ( '\n' ) ;
6792
68- console . log ( 'Total CSS:' , totalStyle ) ;
93+ console . log ( totalStyle ) ;
6994
70- expect ( totalStyle ) . toContain ( '.test-prefix' ) ;
7195 expect ( totalStyle ) . toContain ( '.custom-a' ) ;
7296 expect ( totalStyle ) . toContain ( '.custom-b' ) ;
7397 } ) ;
0 commit comments