|
1 | 1 | import ax from '../ax';
|
2 | 2 |
|
3 | 3 | describe('ax', () => {
|
4 |
| - it('should join single classes together', () => { |
5 |
| - const result = ax(['foo', 'bar']); |
6 |
| - |
7 |
| - expect(result).toEqual('foo bar'); |
8 |
| - }); |
9 |
| - |
10 |
| - it('should join multi classes together', () => { |
11 |
| - const result = ax(['foo baz', 'bar']); |
12 |
| - |
13 |
| - expect(result).toEqual('foo baz bar'); |
14 |
| - }); |
15 |
| - |
16 |
| - it('should remove undefined', () => { |
17 |
| - const result = ax(['foo', 'bar', undefined]); |
18 |
| - |
19 |
| - expect(result).toEqual('foo bar'); |
20 |
| - }); |
21 |
| - |
22 |
| - it('should ensure the last atomic declaration of a single group wins', () => { |
23 |
| - const result = ax(['_aaaabbbb', '_aaaacccc']); |
24 |
| - |
25 |
| - expect(result).toEqual('_aaaacccc'); |
26 |
| - }); |
27 |
| - |
28 |
| - it('should ensure the last atomic declaration of many single groups wins', () => { |
29 |
| - const result = ax(['_aaaabbbb', '_aaaacccc', '_aaaadddd', '_aaaaeeee']); |
30 |
| - |
31 |
| - expect(result).toEqual('_aaaaeeee'); |
32 |
| - }); |
33 |
| - |
34 |
| - it('should ensure the last atomic declaration of a multi group wins', () => { |
35 |
| - const result = ax(['_aaaabbbb _aaaacccc']); |
36 |
| - |
37 |
| - expect(result).toEqual('_aaaacccc'); |
38 |
| - }); |
39 |
| - |
40 |
| - it('should ensure the last atomic declaration of many multi groups wins', () => { |
41 |
| - const result = ax(['_aaaabbbb _aaaacccc _aaaadddd _aaaaeeee']); |
42 |
| - |
43 |
| - expect(result).toEqual('_aaaaeeee'); |
44 |
| - }); |
45 |
| - |
46 |
| - it('should not remove any atomic declarations if there are no duplicate groups', () => { |
47 |
| - const result = ax(['_aaaabbbb', '_bbbbcccc']); |
48 |
| - |
49 |
| - expect(result).toEqual('_aaaabbbb _bbbbcccc'); |
50 |
| - }); |
51 |
| - |
52 |
| - it('should not apply conditional class', () => { |
53 |
| - const isEnabled: boolean = (() => false)(); |
54 |
| - const result = ax([isEnabled && 'foo', 'bar']); |
55 |
| - |
56 |
| - expect(result).toEqual('bar'); |
57 |
| - }); |
58 |
| - |
59 |
| - it('should ignore non atomic declarations', () => { |
60 |
| - const result = ax(['hello_there', 'hello_world']); |
61 |
| - |
62 |
| - expect(result).toEqual('hello_there hello_world'); |
63 |
| - }); |
64 |
| - |
65 |
| - it('should ignore non atomic declarations when atomic declarations exist', () => { |
66 |
| - const result = ax(['hello_there', 'hello_world', '_aaaabbbb']); |
67 |
| - |
68 |
| - expect(result).toEqual('hello_there hello_world _aaaabbbb'); |
| 4 | + const isEnabled: boolean = (() => false)(); |
| 5 | + |
| 6 | + it.each([ |
| 7 | + ['should handle empty array', [], undefined], |
| 8 | + ['should handle array with undefined', [undefined], undefined], |
| 9 | + ['should join single classes together', ['foo', 'bar'], 'foo bar'], |
| 10 | + ['should join multi classes together', ['foo baz', 'bar'], 'foo baz bar'], |
| 11 | + ['should remove undefined', ['foo', 'bar', undefined], 'foo bar'], |
| 12 | + [ |
| 13 | + 'should ensure the last atomic declaration of a single group wins', |
| 14 | + ['_aaaabbbb', '_aaaacccc'], |
| 15 | + '_aaaacccc', |
| 16 | + ], |
| 17 | + [ |
| 18 | + 'should ensure the last atomic declaration of a single group with short class name wins', |
| 19 | + ['_aaaabbbb', '_aaaacccc', '_aaaa_a'], |
| 20 | + 'a', |
| 21 | + ], |
| 22 | + [ |
| 23 | + 'should ensure the last atomic declaration of many single groups wins', |
| 24 | + ['_aaaabbbb', '_aaaacccc', '_aaaadddd', '_aaaaeeee'], |
| 25 | + '_aaaaeeee', |
| 26 | + ], |
| 27 | + [ |
| 28 | + 'should ensure the last atomic declaration of many single groups with short class name wins', |
| 29 | + ['_aaaabbbb', '_aaaacccc', '_aaaa_a', '_aaaa_b'], |
| 30 | + 'b', |
| 31 | + ], |
| 32 | + [ |
| 33 | + 'should ensure the last atomic declaration of a multi group wins', |
| 34 | + ['_aaaabbbb _aaaacccc'], |
| 35 | + '_aaaacccc', |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'should ensure the last atomic declaration of a multi group with short class name wins', |
| 39 | + ['_aaaa_e', '_aaaabbbb _aaaacccc'], |
| 40 | + '_aaaacccc', |
| 41 | + ], |
| 42 | + [ |
| 43 | + 'should ensure the last atomic declaration of many multi groups wins', |
| 44 | + ['_aaaabbbb _aaaacccc _aaaadddd _aaaaeeee'], |
| 45 | + '_aaaaeeee', |
| 46 | + ], |
| 47 | + [ |
| 48 | + 'should ensure the last atomic declaration of many multi groups with short class name wins', |
| 49 | + ['_aaaabbbb', '_aaaa_a', '_bbbb_b', '_ddddcccc'], |
| 50 | + 'a b _ddddcccc', |
| 51 | + ], |
| 52 | + [ |
| 53 | + 'should not remove any atomic declarations if there are no duplicate groups', |
| 54 | + ['_aaaabbbb', '_bbbbcccc'], |
| 55 | + '_aaaabbbb _bbbbcccc', |
| 56 | + ], |
| 57 | + [ |
| 58 | + 'should not remove any atomic declarations if there are short class name and no duplicate groups', |
| 59 | + ['_eeee_e', '_aaaabbbb', '_bbbbcccc'], |
| 60 | + 'e _aaaabbbb _bbbbcccc', |
| 61 | + ], |
| 62 | + ['should not apply conditional class', [isEnabled && 'foo', 'bar'], 'bar'], |
| 63 | + [ |
| 64 | + 'should ignore non atomic declarations', |
| 65 | + ['hello_there', 'hello_world'], |
| 66 | + 'hello_there hello_world', |
| 67 | + ], |
| 68 | + [ |
| 69 | + 'should ignore non atomic declarations when atomic declarations exist', |
| 70 | + ['hello_there', 'hello_world', '_aaaabbbb'], |
| 71 | + 'hello_there hello_world _aaaabbbb', |
| 72 | + ], |
| 73 | + [ |
| 74 | + 'should ignore non atomic declarations when atomic declarations with short class name exist', |
| 75 | + ['hello_there', 'hello_world', '_aaaa_a'], |
| 76 | + 'hello_there hello_world a', |
| 77 | + ], |
| 78 | + ])('%s', (_, params, result) => { |
| 79 | + expect(result).toEqual(ax(params)); |
69 | 80 | });
|
70 | 81 | });
|
0 commit comments