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 fileTake it
chore: import & add testsLuke Edwardsbefore adoption25fcd73
lines 1–4why, one step back1/**2 * Ported from `classnames` for compatibility checks.3 */4chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 5–7why, one step back5import { test } from 'uvu';6import * as assert from 'uvu/assert';7import clsx from '../src';chore: import & add testsLuke Edwardsbefore adoption25fcd73
line 8why, one step back8chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 9–11why, one step back9test('(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 back12});13chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 14–16why, one step back14test('(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 back17});18chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 19–20why, one step back19test('(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 back21});22chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 23–24why, one step back23test('(compat) should be trimmed', () => {24 assert.is(clsx('', 'b', {}, ''), 'b');chore: import & add testsLuke Edwardsbefore adoption25fcd73
lines 25–26why, one step back25});26chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 27–28why, one step back27test('(compat) returns an empty string for an empty configuration', () => {28 assert.is(clsx({}), '');chore: import & add testsLuke Edwardsbefore adoption25fcd73
lines 29–30why, one step back29});30chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 31–32why, one step back31test('(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 back33});34chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 35–37why, one step back35test('(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 back38});39chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 40–41why, one step back40test('(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 back42});43chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 44–45why, one step back44test('(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 back46});47chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 48–49why, one step back48test('(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 back50});51chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 52–53why, one step back52test('(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 back54});55chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 56–57why, one step back56test('(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 back58});59chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 60–61why, one step back60test('(compat) handles arrays that are empty', () => {61 assert.is(clsx('a', []), 'a');chore: import & add testsLuke Edwardsbefore adoption25fcd73
lines 62–63why, one step back62});63chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 64–65why, one step back64test('(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 back66});67chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 68–69why, one step back68test('(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 back70 // 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 });89chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
line 90why, one step back90 assert.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');chore: import & add testsLuke Edwardsbefore adoption25fcd73
line 91why, one step back91});chore: tape -> uvu testsLuke Edwardsbefore adoption1c36d10
lines 92–93why, one step back9293test.run();