@compiled/react
Version:
A familiar and performant compile time CSS-in-JS library for React.
59 lines (56 loc) • 2.06 kB
text/typescript
import ax from '../ax';
describe('ax', () => {
const isEnabled: boolean = (() => false)();
it.each([
['should handle empty array', [], undefined],
['should handle array with undefined', [undefined], undefined],
['should handle array with falsy values', [undefined, null, false as const, ''], undefined],
['should join single classes together', ['foo', 'bar'], 'foo bar'],
['should join multi classes together', ['foo baz', 'bar'], 'foo baz bar'],
['should remove undefined', ['foo', 'bar', undefined], 'foo bar'],
[
'should ensure the last atomic declaration of a single group wins',
['_aaaabbbb', '_aaaacccc'],
'_aaaacccc',
],
[
'should ensure the last atomic declaration of many single groups wins',
['_aaaabbbb', '_aaaacccc', '_aaaadddd', '_aaaaeeee'],
'_aaaaeeee',
],
[
'should ensure the last atomic declaration of a multi group wins',
['_aaaabbbb _aaaacccc'],
'_aaaacccc',
],
[
'should ensure the last atomic declaration of many multi groups wins',
['_aaaabbbb _aaaacccc _aaaadddd _aaaaeeee'],
'_aaaaeeee',
],
[
'should ensure the last atomic declaration of many multi groups with short class name wins',
['_aaaabbbb', '_aaaaaaa', '_ddddbbb', '_ddddcccc'],
'_aaaaaaa _ddddcccc',
],
[
'should not remove any atomic declarations if there are no duplicate groups',
['_aaaabbbb', '_bbbbcccc'],
'_aaaabbbb _bbbbcccc',
],
['should not apply conditional class', [isEnabled && 'foo', 'bar'], 'bar'],
[
'should ignore non atomic declarations',
['hello_there', 'hello_world'],
'hello_there hello_world',
],
[
'should ignore non atomic declarations when atomic declarations exist',
['hello_there', 'hello_world', '_aaaabbbb'],
'hello_there hello_world _aaaabbbb',
],
['should remove duplicate custom class names', ['a', 'a'], 'a'],
])('%s', (_, params, expected) => {
expect(ax(params)).toEqual(expected);
});
});