Skip to content
Myr

classnames.js

This file

Path

test/classnames.js

93 lines · 2.4 KiB · JavaScript

Last changed by

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

History of this file

Take it

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 1–4why, one step back
1/**
2 * Ported from `classnames` for compatibility checks.3 */4

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 5–7why, one step back
5import { test } from 'uvu';
6import * as assert from 'uvu/assert';7import clsx from '../src';

chore: import & add testsLuke Edwardsbefore adoption25fcd73

line 8why, one step back
8

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 9–11why, one step back
9test('(compat) keeps object keys with truthy values', () => {
10 const out = clsx({ a:true, b:false, c:0, d:null, e:undefined, f:1 });11 assert.is(out, 'a f');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 12–13why, one step back
12});
13

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 14–16why, one step back
14test('(compat) joins arrays of class names and ignore falsy values', () => {
15 const out = clsx('a', 0, null, undefined, true, 1, 'b');16 assert.is(out, 'a 1 b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 17–18why, one step back
17});
18

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 19–20why, one step back
19test('(compat) supports heterogenous arguments', () => {
20 assert.is(clsx({ a:true }, 'b', 0), 'a b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 21–22why, one step back
21});
22

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 23–24why, one step back
23test('(compat) should be trimmed', () => {
24 assert.is(clsx('', 'b', {}, ''), 'b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 25–26why, one step back
25});
26

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 27–28why, one step back
27test('(compat) returns an empty string for an empty configuration', () => {
28 assert.is(clsx({}), '');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 29–30why, one step back
29});
30

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 31–32why, one step back
31test('(compat) supports an array of class names', () => {
32 assert.is(clsx(['a', 'b']), 'a b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 33–34why, one step back
33});
34

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 35–37why, one step back
35test('(compat) joins array arguments with string arguments', () => {
36 assert.is(clsx(['a', 'b'], 'c'), 'a b c');37 assert.is(clsx('c', ['a', 'b']), 'c a b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 38–39why, one step back
38});
39

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 40–41why, one step back
40test('(compat) handles multiple array arguments', () => {
41 assert.is(clsx(['a', 'b'], ['c', 'd']), 'a b c d');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 42–43why, one step back
42});
43

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 44–45why, one step back
44test('(compat) handles arrays that include falsy and true values', () => {
45 assert.is(clsx(['a', 0, null, undefined, false, true, 'b']), 'a b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 46–47why, one step back
46});
47

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 48–49why, one step back
48test('(compat) handles arrays that include arrays', () => {
49 assert.is(clsx(['a', ['b', 'c']]), 'a b c');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 50–51why, one step back
50});
51

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 52–53why, one step back
52test('(compat) handles arrays that include objects', () => {
53 assert.is(clsx(['a', { b:true, c:false }]), 'a b');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 54–55why, one step back
54});
55

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 56–57why, one step back
56test('(compat) handles deep array recursion', () => {
57 assert.is(clsx(['a', ['b', ['c', { d:true }]]]), 'a b c d');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 58–59why, one step back
58});
59

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 60–61why, one step back
60test('(compat) handles arrays that are empty', () => {
61 assert.is(clsx('a', []), 'a');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 62–63why, one step back
62});
63

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 64–65why, one step back
64test('(compat) handles nested arrays that have empty nested arrays', () => {
65 assert.is(clsx('a', [[]]), 'a');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 66–67why, one step back
66});
67

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 68–69why, one step back
68test('(compat) handles all types of truthy and falsy property values as expected', () => {
69 const out = clsx({

chore: import & add testsLuke Edwardsbefore adoption25fcd73

lines 70–89why, one step back
70 // falsy:
71 null: null,72 emptyString: '',73 noNumber: NaN,74 zero: 0,75 negativeZero: -0,76 false: false,77 undefined: undefined,7879 // truthy (literally anything else):80 nonEmptyString: 'foobar',81 whitespace: ' ',82 function: Object.prototype.toString,83 emptyObject: {},84 nonEmptyObject: {a: 1, b: 2},85 emptyList: [],86 nonEmptyList: [1, 2, 3],87 greaterZero: 188 });89

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

line 90why, one step back
90 assert.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');

chore: import & add testsLuke Edwardsbefore adoption25fcd73

line 91why, one step back
91});

chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10

lines 92–93why, one step back
92
93test.run();