Skip to content

Commit

Permalink
added case for range syntax in tests for mq range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswalden committed Aug 11, 2020
1 parent 5105cda commit 52767b4
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions index.test.js
Expand Up @@ -198,6 +198,24 @@ gteLteWidthVariants.forEach(description => {
})
})


const inapplicableRangeVariants = [
'(width => N1) and (width <= N2)',
'(min-width: N1) and (max-width: N2)'
// '(N1 <= width =< N2)'
]
inapplicableRangeVariants.forEach(description => {
let conditions = description.replace('N1', '1024px').replace('N2', '768px')
describe(`@media ${conditions}`, () => {
it('removes block with inapplicable range', async () => {
let input = `/* outside */ @media ${conditions} { /* inside */ }`
let result = await run(input)

expect(result).toEqual('/* outside */')
})
})
})

it('leaves unrelated queries untouched', async () => {
let input = `
@media print { /* print styles */ }
Expand All @@ -207,14 +225,3 @@ it('leaves unrelated queries untouched', async () => {
let result = await run(input, { minValue: 480, maxValue: 1280 })
expect(result).toEqual(input)
})

it('removes non-applicable media query', async () => {
let input =
'@media (max-width: 100px) and (min-width: 200px) { /* removed styles */}'
let result = await run(input, {
minValue: 75,
maxValue: 250
})

expect(result).toEqual('')
})

0 comments on commit 52767b4

Please sign in to comment.