@@ -24,9 +24,9 @@ describe("cn function from lite (simple concatenation)", () => {
2424 } ) ;
2525
2626 test ( "should handle nested arrays" , ( ) => {
27- expect ( cnLite ( [ "px-4" , [ "py-2" , [ "bg-blue-500" , [ "rounded-lg" , false , [ "shadow-md" ] ] ] ] ] ) ( ) ) . toBe (
28- "px-4 py-2 bg-blue-500 rounded-lg shadow-md" ,
29- ) ;
27+ expect (
28+ cnLite ( [ "px-4" , [ " py-2" , [ " bg-blue-500" , [ " rounded-lg" , false , [ " shadow-md"] ] ] ] ] ) ( ) ,
29+ ) . toBe ( "px-4 py-2 bg-blue-500 rounded-lg shadow-md" ) ;
3030 } ) ;
3131
3232 test ( "should join objects with truthy values as keys" , ( ) => {
@@ -144,6 +144,68 @@ describe("cn function with tailwind-merge (main index)", () => {
144144
145145 expect ( result ) . toBe ( "px-4" ) ;
146146 } ) ;
147+
148+ test ( "should merge classes by default when called directly without ()" , ( ) => {
149+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ;
150+
151+ // Should work as a string in template literals and string coercion
152+ expect ( String ( result ) ) . toBe ( "px-4 py-2" ) ;
153+ expect ( `${ result } ` ) . toBe ( "px-4 py-2" ) ;
154+ } ) ;
155+
156+ test ( "should merge classes by default when no config is provided" , ( ) => {
157+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ( ) ;
158+
159+ expect ( result ) . toBe ( "px-4 py-2" ) ;
160+ } ) ;
161+
162+ test ( "should merge text color classes by default when called directly" , ( ) => {
163+ const result = cnWithMerge ( "text-red-500" , "text-blue-500" ) ;
164+
165+ expect ( String ( result ) ) . toBe ( "text-blue-500" ) ;
166+ } ) ;
167+
168+ test ( "should merge text color classes by default when no config is provided" , ( ) => {
169+ const result = cnWithMerge ( "text-red-500" , "text-blue-500" ) ( ) ;
170+
171+ expect ( result ) . toBe ( "text-blue-500" ) ;
172+ } ) ;
173+
174+ test ( "should merge background color classes by default when called directly" , ( ) => {
175+ const result = cnWithMerge ( "bg-red-500" , "bg-blue-500" ) ;
176+
177+ expect ( String ( result ) ) . toBe ( "bg-blue-500" ) ;
178+ } ) ;
179+
180+ test ( "should merge background color classes by default when no config is provided" , ( ) => {
181+ const result = cnWithMerge ( "bg-red-500" , "bg-blue-500" ) ( ) ;
182+
183+ expect ( result ) . toBe ( "bg-blue-500" ) ;
184+ } ) ;
185+
186+ test ( "should not merge classes when twMerge is explicitly false" , ( ) => {
187+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ( { twMerge : false } ) ;
188+
189+ expect ( result ) . toBe ( "px-2 px-4 py-2" ) ;
190+ } ) ;
191+
192+ test ( "should merge classes when twMerge is explicitly true (backward compatibility)" , ( ) => {
193+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ( { twMerge : true } ) ;
194+
195+ expect ( result ) . toBe ( "px-4 py-2" ) ;
196+ } ) ;
197+
198+ test ( "should merge classes when config is empty object (defaults to true)" , ( ) => {
199+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ( { } ) ;
200+
201+ expect ( result ) . toBe ( "px-4 py-2" ) ;
202+ } ) ;
203+
204+ test ( "should merge classes when config is undefined" , ( ) => {
205+ const result = cnWithMerge ( "px-2" , "px-4" , "py-2" ) ( undefined ) ;
206+
207+ expect ( result ) . toBe ( "px-4 py-2" ) ;
208+ } ) ;
147209} ) ;
148210
149211describe . each ( cxVariants ) ( "cx function - $name" , ( { cx} ) => {
0 commit comments