Skip to content

Commit 8699f39

Browse files
authored
Merge pull request #773 from tailwindcss/test-screen
Fix @screen not working, add simple test
2 parents 41d1c29 + 048bd04 commit 8699f39

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

__tests__/screenAtRule.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import postcss from 'postcss'
2+
import plugin from '../src/lib/substituteScreenAtRules'
3+
import config from '../stubs/defaultConfig.stub.js'
4+
5+
function run(input, opts = config) {
6+
return postcss([plugin(opts)]).process(input, { from: undefined })
7+
}
8+
9+
test('it can generate media queries from configured screen sizes', () => {
10+
const input = `
11+
@screen sm {
12+
.banana { color: yellow; }
13+
}
14+
@screen md {
15+
.banana { color: red; }
16+
}
17+
@screen lg {
18+
.banana { color: green; }
19+
}
20+
`
21+
22+
const output = `
23+
@media (min-width: 500px) {
24+
.banana { color: yellow; }
25+
}
26+
@media (min-width: 750px) {
27+
.banana { color: red; }
28+
}
29+
@media (min-width: 1000px) {
30+
.banana { color: green; }
31+
}
32+
`
33+
34+
return run(input, {
35+
theme: {
36+
screens: {
37+
sm: '500px',
38+
md: '750px',
39+
lg: '1000px',
40+
},
41+
},
42+
separator: ':',
43+
}).then(result => {
44+
expect(result.css).toMatchCss(output)
45+
expect(result.warnings().length).toBe(0)
46+
})
47+
})

src/lib/substituteScreenAtRules.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import _ from 'lodash'
22
import buildMediaQuery from '../util/buildMediaQuery'
33

4-
export default function(config) {
4+
export default function({ theme }) {
55
return function(css) {
66
css.walkAtRules('screen', atRule => {
77
const screen = atRule.params
88

9-
if (!_.has(config.screens, screen)) {
9+
if (!_.has(theme.screens, screen)) {
1010
throw atRule.error(`No \`${screen}\` screen found.`)
1111
}
1212

1313
atRule.name = 'media'
14-
atRule.params = buildMediaQuery(config.screens[screen])
14+
atRule.params = buildMediaQuery(theme.screens[screen])
1515
})
1616
}
1717
}

0 commit comments

Comments
 (0)