Add helper for testing utility plugins
This commit is contained in:
parent
915d9c60e5
commit
921e2ff202
1 changed files with 29 additions and 0 deletions
29
__tests__/plugins/util/invokePlugin.js
Normal file
29
__tests__/plugins/util/invokePlugin.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import _ from 'lodash'
|
||||
import escapeClassName from '../../../src/util/escapeClassName'
|
||||
|
||||
export default function(plugin, config) {
|
||||
const addedUtilities = []
|
||||
|
||||
const getConfigValue = (path, defaultValue) => _.get(config, path, defaultValue)
|
||||
const pluginApi = {
|
||||
config: getConfigValue,
|
||||
e: escapeClassName,
|
||||
theme: (path, defaultValue) => getConfigValue(`theme.${path}`, defaultValue),
|
||||
variants: (path, defaultValue) => {
|
||||
if (_.isArray(config.variants)) {
|
||||
return config.variants
|
||||
}
|
||||
|
||||
return getConfigValue(`variants.${path}`, defaultValue)
|
||||
},
|
||||
addUtilities(utilities, variants) {
|
||||
addedUtilities.push([utilities, variants])
|
||||
},
|
||||
}
|
||||
|
||||
plugin(pluginApi)
|
||||
|
||||
return {
|
||||
utilities: addedUtilities,
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue