File tree Expand file tree Collapse file tree 2 files changed +87
-2
lines changed Expand file tree Collapse file tree 2 files changed +87
-2
lines changed Original file line number Diff line number Diff line change @@ -1570,3 +1570,88 @@ test('plugins created using `createPlugin.withOptions` do not need to be invoked
1570
1570
expect ( result . css ) . toMatchCss ( expected )
1571
1571
} )
1572
1572
} )
1573
+
1574
+ test ( 'the configFunction parameter is optional when using the `createPlugin.withOptions` function' , ( ) => {
1575
+ const plugin = createPlugin . withOptions ( function ( { className } ) {
1576
+ return function ( { addUtilities, theme, variants } ) {
1577
+ const utilities = _ . fromPairs (
1578
+ _ . toPairs ( theme ( 'testPlugin' ) ) . map ( ( [ k , v ] ) => [ `.${ className } -${ k } ` , { testProperty : v } ] )
1579
+ )
1580
+
1581
+ addUtilities ( utilities , variants ( 'testPlugin' ) )
1582
+ }
1583
+ } )
1584
+
1585
+ return _postcss ( [
1586
+ tailwind ( {
1587
+ corePlugins : [ ] ,
1588
+ theme : {
1589
+ screens : {
1590
+ sm : '400px' ,
1591
+ } ,
1592
+ testPlugin : {
1593
+ sm : '1px' ,
1594
+ md : '2px' ,
1595
+ lg : '3px' ,
1596
+ } ,
1597
+ } ,
1598
+ variants : {
1599
+ testPlugin : [ 'responsive' , 'focus' ] ,
1600
+ } ,
1601
+ plugins : [ plugin ( { className : 'banana' } ) ] ,
1602
+ } ) ,
1603
+ ] )
1604
+ . process (
1605
+ `
1606
+ @tailwind base;
1607
+ @tailwind components;
1608
+ @tailwind utilities;
1609
+ ` ,
1610
+ { from : undefined }
1611
+ )
1612
+ . then ( result => {
1613
+ const expected = `
1614
+ .banana-sm {
1615
+ test-property: 1px
1616
+ }
1617
+ .banana-md {
1618
+ test-property: 2px
1619
+ }
1620
+ .banana-lg {
1621
+ test-property: 3px
1622
+ }
1623
+ .focus\\:banana-sm:focus {
1624
+ test-property: 1px
1625
+ }
1626
+ .focus\\:banana-md:focus {
1627
+ test-property: 2px
1628
+ }
1629
+ .focus\\:banana-lg:focus {
1630
+ test-property: 3px
1631
+ }
1632
+
1633
+ @media (min-width: 400px) {
1634
+ .sm\\:banana-sm {
1635
+ test-property: 1px
1636
+ }
1637
+ .sm\\:banana-md {
1638
+ test-property: 2px
1639
+ }
1640
+ .sm\\:banana-lg {
1641
+ test-property: 3px
1642
+ }
1643
+ .sm\\:focus\\:banana-sm:focus {
1644
+ test-property: 1px
1645
+ }
1646
+ .sm\\:focus\\:banana-md:focus {
1647
+ test-property: 2px
1648
+ }
1649
+ .sm\\:focus\\:banana-lg:focus {
1650
+ test-property: 3px
1651
+ }
1652
+ }
1653
+ `
1654
+
1655
+ expect ( result . css ) . toMatchCss ( expected )
1656
+ } )
1657
+ } )
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ function createPlugin(plugin, config) {
5
5
}
6
6
}
7
7
8
- createPlugin . withOptions = function ( pluginFunction , configFunction ) {
8
+ createPlugin . withOptions = function ( pluginFunction , configFunction = ( ) => ( { } ) ) {
9
9
const optionsFunction = function ( options ) {
10
10
return {
11
11
handler : pluginFunction ( options ) ,
12
- config : configFunction ? configFunction ( options ) : { } ,
12
+ config : configFunction ( options ) ,
13
13
}
14
14
}
15
15
You can’t perform that action at this time.
0 commit comments