Add test, fix style

This commit is contained in:
Adam Wathan 2019-05-27 08:05:51 +02:00
parent 6ce2cfe349
commit 5e7c263e0a
2 changed files with 35 additions and 4 deletions

View File

@ -123,6 +123,32 @@ test('it parses nested media queries', () => {
`)
})
test('it bubbles nested screen rules', () => {
const result = parseObjectStyles({
'.foo': {
backgroundColor: 'red',
color: 'white',
padding: '1rem',
'@screen sm': {
backgroundColor: 'orange',
},
},
})
expect(css(result)).toMatchCss(`
.foo {
background-color: red;
color: white;
padding: 1rem;
}
@screen sm {
.foo {
background-color: orange;
}
}
`)
})
test('it parses pseudo-selectors in nested media queries', () => {
const result = parseObjectStyles({
'.foo': {

View File

@ -8,8 +8,13 @@ export default function parseObjectStyles(styles) {
return parseObjectStyles([styles])
}
return _.flatMap(
styles,
style => postcss([postcssNested({ bubble: ['screen'] })]).process(style, { parser: postcssJs }).root.nodes
)
return _.flatMap(styles, style => {
return postcss([
postcssNested({
bubble: ['screen'],
}),
]).process(style, {
parser: postcssJs,
}).root.nodes
})
}