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

54 lines
1,010 B
JavaScript
Raw Permalink Normal View History

2019-04-11 12:14:27 +00:00
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
2019-05-01 18:40:39 +00:00
const plugin = require('./index')
2019-04-11 12:14:27 +00:00
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
2019-05-02 00:51:43 +00:00
function run(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
})
}
expect.extend({
toMatchCss: cssMatcher
})
2019-04-11 19:59:01 +00:00
test('it generates the correct classes with no variants', () => {
2019-05-02 00:49:20 +00:00
const output = `
.test {
display: block
}
`
2019-05-02 00:51:43 +00:00
run().then(result => {
2019-05-02 00:49:20 +00:00
expect(result.css).toMatchCss(output)
2019-04-11 12:14:27 +00:00
})
})
2019-04-11 19:59:01 +00:00
test('it generates the correct classes with variants', () => {
2019-05-02 00:49:20 +00:00
const output = `
.test {
display: block
}
.hover\\:test:hover {
display: block
}
.focus\\:test:focus {
display: block
}
`
2019-05-02 00:51:43 +00:00
run({ variants: ['hover', 'focus'] }).then(result => {
2019-05-02 00:49:20 +00:00
expect(result.css).toMatchCss(output)
2019-04-11 19:59:01 +00:00
})
})