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

51 lines
1 KiB
JavaScript
Raw Normal View History

2019-04-11 12:14:27 +00:00
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
const plugin = require('./index.js')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
2019-04-11 19:59:01 +00:00
const generatePluginCss = (options = {}) => {
2019-04-11 12:14:27 +00:00
return postcss(
tailwindcss({
2019-04-23 20:41:38 +00:00
corePlugins: false,
2019-04-11 19:59:01 +00:00
plugins: [plugin(options)]
2019-04-11 12:14:27 +00:00
})
)
.process('@tailwind utilities;', {
from: undefined
})
2019-05-01 18:38:06 +00:00
.then(result => result.css)
2019-04-11 12:14:27 +00:00
}
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
}
`)
})
})