@@ -50,6 +50,15 @@ describe('babel-prefix-react-classnames', () => {
5050 expect ( result ) . toContain ( 'className: `prefix-foo ${dynamic} prefix-bar`' ) ;
5151 } ) ;
5252
53+ it ( 'should handle continuous class names in template literals with expressions' , ( ) => {
54+ const code =
55+ '<div className={`foo${isLarge ? "-large" : ""}-bar prefix-blah ${active && "active"}`}>Hello</div>' ;
56+ const result = transform ( code ) ;
57+ expect ( result ) . toContain (
58+ 'className: `prefix-foo${isLarge ? "-large" : ""}-bar prefix-blah ${active && "active"}`' ,
59+ ) ;
60+ } ) ;
61+
5362 it ( 'should handle identifiers by using the helper function' , ( ) => {
5463 const code = '<div className={classes}>Hello</div>' ;
5564 const result = transform ( code ) ;
@@ -76,6 +85,26 @@ describe('babel-prefix-react-classnames', () => {
7685 expect ( result ) . toContain ( '"prefix-bar"' ) ;
7786 } ) ;
7887
88+ it ( 'should ensure helper function is only added once' , ( ) => {
89+ const code = `
90+ <div>
91+ <div className={styles.container}>First</div>
92+ <span className={otherStyles.text}>Second</span>
93+ <button className={btnStyles.button}>Third</button>
94+ </div>
95+ ` ;
96+ const result = transform ( code ) ;
97+
98+ // Helper function should be defined only once
99+ const helperMatches = result . match ( / f u n c t i o n _ _ p r e f i x C l a s s N a m e s \( v a l u e \) / g) ;
100+ expect ( helperMatches ) . toHaveLength ( 1 ) ;
101+
102+ // All three elements should use the helper
103+ expect ( result ) . toContain ( 'className: __prefixClassNames(styles.container)' ) ;
104+ expect ( result ) . toContain ( 'className: __prefixClassNames(otherStyles.text)' ) ;
105+ expect ( result ) . toContain ( 'className: __prefixClassNames(btnStyles.button)' ) ;
106+ } ) ;
107+
79108 it ( 'should handle cn utility function calls with variables' , ( ) => {
80109 const code = '<div className={cn(classes, "bar")}>Hello</div>' ;
81110 const result = transform ( code ) ;
0 commit comments