lab/tailwindcss-plugin-jest/test.js

54 lines
1,010 B
JavaScript
Raw Normal View History

2019-04-11 13:14:27 +01:00
const cssMatcher = require('jest-matcher-css')
const defaultConfig = require('tailwindcss/defaultConfig')
2019-05-01 19:40:39 +01:00
const plugin = require('./index')
2019-04-11 13:14:27 +01:00
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')
2019-05-02 01:51:43 +01:00
function run(options = {}) {
2019-04-11 13:14:27 +01:00
return postcss(
tailwindcss({
2019-04-23 21:41:38 +01:00
corePlugins: false,
2019-04-11 20:59:01 +01:00
plugins: [plugin(options)]
2019-04-11 13:14:27 +01:00
})
)
.process('@tailwind utilities;', {
from: undefined
})
}
expect.extend({
toMatchCss: cssMatcher
})
2019-04-11 20:59:01 +01:00
test('it generates the correct classes with no variants', () => {
2019-05-02 01:49:20 +01:00
const output = `
.test {
display: block
}
`
2019-05-02 01:51:43 +01:00
run().then(result => {
2019-05-02 01:49:20 +01:00
expect(result.css).toMatchCss(output)
2019-04-11 13:14:27 +01:00
})
})
2019-04-11 20:59:01 +01:00
test('it generates the correct classes with variants', () => {
2019-05-02 01:49:20 +01:00
const output = `
.test {
display: block
}
.hover\\:test:hover {
display: block
}
.focus\\:test:focus {
display: block
}
`
2019-05-02 01:51:43 +01:00
run({ variants: ['hover', 'focus'] }).then(result => {
2019-05-02 01:49:20 +01:00
expect(result.css).toMatchCss(output)
2019-04-11 20:59:01 +01:00
})
})