tailwindcss/__tests__/applyAtRule.test.js
Adam Wathan 538a854a73 Don't allow applying classes that appear in multiple rulesets
This can result in unexpected behavior, so explicitly erroring is best.
We can of course add support for this later if we see real value in it
and can come up with predictable rules for how it should work.
2017-11-16 07:54:40 -05:00

78 lines
1.5 KiB
JavaScript

import postcss from 'postcss'
import plugin from '../src/lib/substituteClassApplyAtRules'
function run(input, opts = () => {}) {
return postcss([plugin(opts)]).process(input)
}
test("it copies a class's declarations into itself", () => {
const output = '.a { color: red; } .b { color: red; }'
return run('.a { color: red; } .b { @apply .a; }').then(result => {
expect(result.css).toEqual(output)
expect(result.warnings().length).toBe(0)
})
})
test('it fails if the class does not exist', () => {
return run('.b { @apply .a; }').catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
})
test('applying classes that are ever used in a media query is not supported', () => {
const input = `
.a {
color: red;
}
@media (min-width: 300px) {
.a { color: blue; }
}
.b {
@apply .a;
}
`
expect.assertions(1)
return run(input).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
})
test('it does not match classes that include pseudo-selectors', () => {
const input = `
.a:hover {
color: red;
}
.b {
@apply .a;
}
`
expect.assertions(1)
return run(input).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
})
test('it does not match classes that have multiple rules', () => {
const input = `
.a {
color: red;
}
.b {
@apply .a;
}
.a {
color: blue;
}
`
expect.assertions(1)
return run(input).catch(e => {
expect(e).toMatchObject({ name: 'CssSyntaxError' })
})
})