@@ -635,49 +635,138 @@ test('you can apply classes to rules within at-rules', () => {
635635 } )
636636} )
637637
638- test . skip ( 'you can apply utility classes without using the given prefix' , ( ) => {
639- const input = `
640- .foo { @apply .tw-mt-4 .mb-4; }
641- `
638+ describe ( 'using apply with the prefix option' , ( ) => {
639+ test ( 'applying a class including the prefix' , ( ) => {
640+ const input = `
641+ .foo { @apply tw-mt-4; }
642+ `
642643
643- const expected = `
644- .foo { margin-top: 1rem; margin-bottom : 1rem; }
645- `
644+ const expected = `
645+ .foo { margin-top: 1rem; }
646+ `
646647
647- const config = resolveConfig ( [
648- {
649- ...defaultConfig ,
650- prefix : 'tw-' ,
651- } ,
652- ] )
648+ const config = resolveConfig ( [
649+ {
650+ ...defaultConfig ,
651+ prefix : 'tw-' ,
652+ } ,
653+ ] )
653654
654- return run ( input , config , processPlugins ( corePlugins ( config ) , config ) . utilities ) . then ( result => {
655- expect ( result . css ) . toMatchCss ( expected )
656- expect ( result . warnings ( ) . length ) . toBe ( 0 )
655+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . then ( result => {
656+ expect ( result . css ) . toMatchCss ( expected )
657+ expect ( result . warnings ( ) . length ) . toBe ( 0 )
658+ } )
657659 } )
658- } )
659660
660- test . skip ( 'you can apply utility classes without using the given prefix when using a function for the prefix', ( ) => {
661- const input = `
662- .foo { @apply . tw-mt-4 .mb -4; }
663- `
661+ test ( 'applying a class including the prefix when using a prefix function ', ( ) => {
662+ const input = `
663+ .foo { @apply tw-func-mt -4; }
664+ `
664665
665- const expected = `
666- .foo { margin-top: 1rem; margin-bottom : 1rem; }
667- `
666+ const expected = `
667+ .foo { margin-top: 1rem; }
668+ `
668669
669- const config = resolveConfig ( [
670- {
671- ...defaultConfig ,
672- prefix : ( ) => {
673- return 'tw-'
670+ const config = resolveConfig ( [
671+ {
672+ ...defaultConfig ,
673+ prefix : ( ) => {
674+ return 'tw-func-'
675+ } ,
674676 } ,
675- } ,
676- ] )
677+ ] )
677678
678- return run ( input , config , processPlugins ( corePlugins ( config ) , config ) . utilities ) . then ( result => {
679- expect ( result . css ) . toMatchCss ( expected )
680- expect ( result . warnings ( ) . length ) . toBe ( 0 )
679+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . then ( result => {
680+ expect ( result . css ) . toMatchCss ( expected )
681+ expect ( result . warnings ( ) . length ) . toBe ( 0 )
682+ } )
683+ } )
684+
685+ test ( 'applying a class without the prefix fails' , ( ) => {
686+ const input = `
687+ .foo { @apply mt-4; }
688+ `
689+
690+ const config = resolveConfig ( [
691+ {
692+ ...defaultConfig ,
693+ prefix : 'tw-' ,
694+ } ,
695+ ] )
696+
697+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . catch ( e => {
698+ expect ( e ) . toMatchObject ( { name : 'CssSyntaxError' } )
699+ } )
700+ } )
701+
702+ test ( 'custom classes with no prefix can be applied' , ( ) => {
703+ const input = `
704+ .foo { @apply mt-4; }
705+ .mt-4 { color: red; }
706+ `
707+
708+ const expected = `
709+ .foo { color: red; }
710+ .mt-4 { color: red; }
711+ `
712+
713+ const config = resolveConfig ( [
714+ {
715+ ...defaultConfig ,
716+ prefix : 'tw-' ,
717+ } ,
718+ ] )
719+
720+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . then ( result => {
721+ expect ( result . css ) . toMatchCss ( expected )
722+ expect ( result . warnings ( ) . length ) . toBe ( 0 )
723+ } )
724+ } )
725+
726+ test ( 'built-in prefixed utilities can be extended and applied' , ( ) => {
727+ const input = `
728+ .foo { @apply tw-mt-4; }
729+ .tw-mt-4 { color: red; }
730+ `
731+
732+ const expected = `
733+ .foo { margin-top: 1rem; color: red; }
734+ .tw-mt-4 { color: red; }
735+ `
736+
737+ const config = resolveConfig ( [
738+ {
739+ ...defaultConfig ,
740+ prefix : 'tw-' ,
741+ } ,
742+ ] )
743+
744+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . then ( result => {
745+ expect ( result . css ) . toMatchCss ( expected )
746+ expect ( result . warnings ( ) . length ) . toBe ( 0 )
747+ } )
748+ } )
749+
750+ test ( 'a helpful error message is provided if it appears the user forgot to include their prefix' , ( ) => {
751+ const input = `
752+ .foo { @apply mt-4; }
753+ `
754+
755+ const config = resolveConfig ( [
756+ {
757+ ...defaultConfig ,
758+ prefix : 'tw-' ,
759+ } ,
760+ ] )
761+
762+ expect . assertions ( 1 )
763+
764+ return run ( input , config , ( ) => processPlugins ( corePlugins ( config ) , config ) ) . catch ( e => {
765+ expect ( e ) . toMatchObject ( {
766+ name : 'CssSyntaxError' ,
767+ reason : 'The `mt-4` class does not exist, but `tw-mt-4` does. Did you forget the prefix?' ,
768+ } )
769+ } )
681770 } )
682771} )
683772
0 commit comments