mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
commit
2699b96cfd
53
__tests__/applyAtRule.test.js
Normal file
53
__tests__/applyAtRule.test.js
Normal file
@ -0,0 +1,53 @@
|
||||
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 doesn't copy a media query definition into itself", () => {
|
||||
const output = `.a {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@media (min-width: 300px) {
|
||||
.a { color: blue; }
|
||||
}
|
||||
|
||||
.b {
|
||||
color: red;
|
||||
}`
|
||||
|
||||
return run(
|
||||
`.a {
|
||||
color: red;
|
||||
}
|
||||
|
||||
@media (min-width: 300px) {
|
||||
.a { color: blue; }
|
||||
}
|
||||
|
||||
.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', () => {
|
||||
run('.b { @apply .a; }', {}).catch(error => {
|
||||
expect(error.reason).toEqual('No .a class found.')
|
||||
})
|
||||
})
|
||||
@ -4,7 +4,7 @@ export default function findMixin(css, mixin, onError) {
|
||||
const matches = []
|
||||
|
||||
css.walkRules(rule => {
|
||||
if (rule.selectors.includes(mixin)) {
|
||||
if (rule.selectors.includes(mixin) && rule.parent.type == 'root') {
|
||||
matches.push(rule)
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user