tailwindcss-plugin-jest-exa.../test.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-04-11 12:14:27 +00:00
const _ = require('lodash')
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
const plugin = require('./index.js')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
const disableCorePlugins = () => {
2019-04-16 12:25:01 +00:00
return _.mapValues(defaultConfig.variants, () => false)
2019-04-11 12:14:27 +00:00
}
2019-04-11 19:59:01 +00:00
const generatePluginCss = (options = {}) => {
2019-04-11 12:14:27 +00:00
return postcss(
tailwindcss({
corePlugins: disableCorePlugins(),
2019-04-11 19:59:01 +00:00
plugins: [plugin(options)]
2019-04-11 12:14:27 +00:00
})
)
.process('@tailwind utilities;', {
from: undefined
})
.then(result => {
return result.css
})
}
expect.extend({
toMatchCss: cssMatcher
})
2019-04-11 19:59:01 +00:00
test('it generates the correct classes with no variants', () => {
2019-04-11 12:14:27 +00:00
return generatePluginCss().then(css => {
expect(css).toMatchCss(`
.test {
2019-04-23 20:41:00 +00:00
display: block
2019-04-11 12:14:27 +00:00
}
`)
})
})
2019-04-11 19:59:01 +00:00
test('it generates the correct classes with variants', () => {
return generatePluginCss({ variants: ['hover', 'focus'] }).then(css => {
expect(css).toMatchCss(`
.test {
2019-04-23 20:41:00 +00:00
display: block
2019-04-11 19:59:01 +00:00
}
.hover\\:test:hover {
2019-04-23 20:41:00 +00:00
display: block
2019-04-11 19:59:01 +00:00
}
.focus\\:test:focus {
2019-04-23 20:41:00 +00:00
display: block
2019-04-11 19:59:01 +00:00
}
`)
})
})