@@ -910,6 +910,196 @@ it('should be possible to apply a class from another rule with multiple selector
910910 } )
911911} )
912912
913+ describe ( 'multiple instances' , ( ) => {
914+ it ( 'should be possible to apply multiple "instances" of the same class' , ( ) => {
915+ let config = {
916+ content : [ { raw : html `` } ] ,
917+ plugins : [ ] ,
918+ corePlugins : { preflight : false } ,
919+ }
920+
921+ let input = css `
922+ .a {
923+ @apply b;
924+ }
925+
926+ .b {
927+ @apply uppercase;
928+ }
929+
930+ .b {
931+ color : red;
932+ }
933+ `
934+
935+ return run ( input , config ) . then ( ( result ) => {
936+ return expect ( result . css ) . toMatchFormattedCss ( css `
937+ .a {
938+ text-transform : uppercase;
939+ color : red;
940+ }
941+
942+ .b {
943+ text-transform : uppercase;
944+ color : red;
945+ }
946+ ` )
947+ } )
948+ } )
949+
950+ it ( 'should be possible to apply a combination of multiple "instances" of the same class' , ( ) => {
951+ let config = {
952+ content : [ { raw : html `` } ] ,
953+ plugins : [ ] ,
954+ corePlugins : { preflight : false } ,
955+ }
956+
957+ let input = css `
958+ .a {
959+ @apply b;
960+ }
961+
962+ .b {
963+ @apply uppercase;
964+ color : red;
965+ }
966+ `
967+
968+ return run ( input , config ) . then ( ( result ) => {
969+ return expect ( result . css ) . toMatchFormattedCss ( css `
970+ .a {
971+ text-transform : uppercase;
972+ color : red;
973+ }
974+
975+ .b {
976+ text-transform : uppercase;
977+ color : red;
978+ }
979+ ` )
980+ } )
981+ } )
982+
983+ it ( 'should generate the same output, even if it was used in a @layer' , ( ) => {
984+ let config = {
985+ content : [ { raw : html `<div class= "a b" > </ div> ` } ] ,
986+ plugins : [ ] ,
987+ corePlugins : { preflight : false } ,
988+ }
989+
990+ let input = css `
991+ @tailwind components;
992+
993+ @layer components {
994+ .a {
995+ @apply b;
996+ }
997+
998+ .b {
999+ @apply uppercase;
1000+ color : red;
1001+ }
1002+ }
1003+ `
1004+
1005+ return run ( input , config ) . then ( ( result ) => {
1006+ return expect ( result . css ) . toMatchFormattedCss ( css `
1007+ .a {
1008+ text-transform : uppercase;
1009+ color : red;
1010+ }
1011+
1012+ .b {
1013+ text-transform : uppercase;
1014+ color : red;
1015+ }
1016+ ` )
1017+ } )
1018+ } )
1019+
1020+ it ( 'should be possible to apply a combination of multiple "instances" of the same class (defined in a layer)' , ( ) => {
1021+ let config = {
1022+ content : [ { raw : html `<div class= "a b" > </ div> ` } ] ,
1023+ plugins : [ ] ,
1024+ corePlugins : { preflight : false } ,
1025+ }
1026+
1027+ let input = css `
1028+ @tailwind components;
1029+
1030+ @layer components {
1031+ .a {
1032+ color : red;
1033+ @apply b;
1034+ color : blue;
1035+ }
1036+
1037+ .b {
1038+ @apply text-green-500;
1039+ text-decoration : underline;
1040+ }
1041+ }
1042+ `
1043+
1044+ return run ( input , config ) . then ( ( result ) => {
1045+ return expect ( result . css ) . toMatchFormattedCss ( css `
1046+ .a {
1047+ color : red;
1048+ --tw-text-opacity : 1 ;
1049+ color : rgb (34 197 94 / var (--tw-text-opacity ));
1050+ text-decoration : underline;
1051+ color : blue;
1052+ }
1053+
1054+ .b {
1055+ --tw-text-opacity : 1 ;
1056+ color : rgb (34 197 94 / var (--tw-text-opacity ));
1057+ text-decoration : underline;
1058+ }
1059+ ` )
1060+ } )
1061+ } )
1062+
1063+ it ( 'should properly maintain the order' , ( ) => {
1064+ let config = {
1065+ content : [ { raw : html `` } ] ,
1066+ plugins : [ ] ,
1067+ corePlugins : { preflight : false } ,
1068+ }
1069+
1070+ let input = css `
1071+ h2 {
1072+ @apply text-xl;
1073+ @apply lg:text-3xl;
1074+ @apply sm:text-2xl;
1075+ }
1076+ `
1077+
1078+ return run ( input , config ) . then ( ( result ) => {
1079+ return expect ( result . css ) . toMatchFormattedCss ( css `
1080+ h2 {
1081+ font-size : 1.25rem ;
1082+ line-height : 1.75rem ;
1083+ }
1084+
1085+ @media (min-width : 1024px ) {
1086+ h2 {
1087+ font-size : 1.875rem ;
1088+ line-height : 2.25rem ;
1089+ }
1090+ }
1091+
1092+ @media (min-width : 640px ) {
1093+ h2 {
1094+ font-size : 1.5rem ;
1095+ line-height : 2rem ;
1096+ }
1097+ }
1098+ ` )
1099+ } )
1100+ } )
1101+ } )
1102+
9131103/*
9141104it('apply can emit defaults in isolated environments without @tailwind directives', () => {
9151105 let config = {
0 commit comments