|
1 |
| -/* global describe it */ |
2 | 1 | import postcss from 'postcss';
|
3 |
| -import {expect} from 'chai'; |
| 2 | +import test from 'ava'; |
4 | 3 | import plugin from '../lib/index';
|
5 |
| -const test = (input, output, opts) => { |
6 |
| - expect(postcss([plugin(opts)]).process(input).css).to.eql(output); |
| 4 | + |
| 5 | +const processing = (input, opts) => { |
| 6 | + return postcss([plugin(opts)]).process(input).css; |
7 | 7 | };
|
8 | 8 |
|
9 |
| -describe('postcss-at-rules-variables', () => { |
10 |
| - it('it change first properties for @for', () => { |
11 |
| - test( |
12 |
| - ':root{ --from: 1; } @for $i from var(--from) to 2', |
13 |
| - ':root{ --from: 1; } @for $i from 1 to 2' |
14 |
| - ); |
15 |
| - }); |
| 9 | +test('it change first properties for @for', t => { |
| 10 | + const expected = ':root{ --from: 1; } @for $i from 1 to 2'; |
| 11 | + const value = ':root{ --from: 1; } @for $i from var(--from) to 2'; |
| 12 | + t.is(processing(value), expected); |
| 13 | +}); |
16 | 14 |
|
17 |
| - it('it change second properties for @for', () => { |
18 |
| - test( |
19 |
| - ':root{ --to: 2; } @for $i from 1 to var(--to)', |
20 |
| - ':root{ --to: 2; } @for $i from 1 to 2' |
21 |
| - ); |
22 |
| - }); |
| 15 | +test('it change second properties for @for', t => { |
| 16 | + const expected = ':root{ --to: 2; } @for $i from 1 to 2'; |
| 17 | + const value = ':root{ --to: 2; } @for $i from 1 to var(--to)'; |
| 18 | + t.is(processing(value), expected); |
| 19 | +}); |
23 | 20 |
|
24 |
| - it('it change two properties for @for', () => { |
25 |
| - test( |
26 |
| - ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)', |
27 |
| - ':root{ --from: 1; --to: 2; } @for $i from 1 to 2' |
28 |
| - ); |
29 |
| - }); |
| 21 | +test('it change two properties for @for', t => { |
| 22 | + const expected = ':root{ --from: 1; --to: 2; } @for $i from 1 to 2'; |
| 23 | + const value = ':root{ --from: 1; --to: 2; } @for $i from var(--from) to var(--to)'; |
| 24 | + t.is(processing(value), expected); |
| 25 | +}); |
30 | 26 |
|
31 |
| - it('it change three properties for @for', () => { |
32 |
| - test( |
33 |
| - ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)', |
34 |
| - ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5' |
35 |
| - ); |
36 |
| - }); |
| 27 | +test('it change three properties for @for', t => { |
| 28 | + const expected = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from 1 to 2 by 5'; |
| 29 | + const value = ':root{ --from: 1; --to: 2; --step: 5 } @for $i from var(--from) to var(--to) by var(--step)'; |
| 30 | + t.is(processing(value), expected); |
| 31 | +}); |
37 | 32 |
|
38 |
| - it('it change two properties for @if', () => { |
39 |
| - test( |
40 |
| - ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)', |
41 |
| - ':root{ --first: 1; --second: 2; } @if 1 < 2', |
42 |
| - {atRules: ['if']} |
43 |
| - ); |
44 |
| - }); |
| 33 | +test('it change two properties for @if', t => { |
| 34 | + const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2'; |
| 35 | + const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second)'; |
| 36 | + t.is(processing(value, {atRules: ['if']}), expected); |
| 37 | +}); |
45 | 38 |
|
46 |
| - it('it change two properties for @if, @else if', () => { |
47 |
| - test( |
48 |
| - ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }', |
49 |
| - ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }', |
50 |
| - {atRules: ['if', 'else']} |
51 |
| - ); |
52 |
| - }); |
| 39 | +test('it change two properties for @if, @else if', t => { |
| 40 | + const expected = ':root{ --first: 1; --second: 2; } @if 1 < 2 { color: olive; } @else if 1 > 2 { color: red; }'; |
| 41 | + const value = ':root{ --first: 1; --second: 2; } @if var(--first) < var(--second) { color: olive; } @else if var(--first) > var(--second) { color: red; }'; |
| 42 | + t.is(processing(value, {atRules: ['if', 'else']}), expected); |
| 43 | +}); |
53 | 44 |
|
54 |
| - it('it change multi properties for @each', () => { |
55 |
| - test( |
56 |
| - ':root{ --array: foo, bar, baz; } @each $val in var(--array)', |
57 |
| - ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz', |
58 |
| - {atRules: ['each']} |
59 |
| - ); |
60 |
| - }); |
| 45 | +test('it change multi properties for @each', t => { |
| 46 | + const expected = ':root{ --array: foo, bar, baz; } @each $val in foo, bar, baz'; |
| 47 | + const value = ':root{ --array: foo, bar, baz; } @each $val in var(--array)'; |
| 48 | + t.is(processing(value, {atRules: ['each']}), expected); |
| 49 | +}); |
61 | 50 |
|
62 |
| - it('it without variables', () => { |
63 |
| - test( |
64 |
| - ':root{ --red: red; } @if var(--green) { color: var(--green) }', |
65 |
| - ':root{ --red: red; } @if var(--green) { color: var(--green) }' |
66 |
| - ); |
67 |
| - }); |
| 51 | +test('it without variables', t => { |
| 52 | + const expected = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
| 53 | + const value = ':root{ --red: red; } @if var(--green) { color: var(--green) }'; |
| 54 | + t.is(processing(value), expected); |
68 | 55 | });
|
0 commit comments