Skip to content
Myr

chore: import & add tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Luke Edwards · committed by Luke Edwards · parent 30520d3 · Browse files · 2 files+170 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+170 added−0 removed

  • tests:+170 added−0 removed

2 files+170 added−0 removed

added:test/classnames.js+105 added
1/**2 * Ported from `classnames` for compatibility checks.3 */45const test = require('tape');6const fn = require('../dist/clsx');78test('(compat) keeps object keys with truthy values', t => {9 const out = fn({ a:true, b:false, c:0, d:null, e:undefined, f:1 });10 t.is(out, 'a f');11 t.end();12});1314test('(compat) joins arrays of class names and ignore falsy values', t => {15 const out = fn('a', 0, null, undefined, true, 1, 'b');16 t.is(out, 'a 1 b');17 t.end();18});1920test('(compat) supports heterogenous arguments', t => {21 t.is(fn({ a:true }, 'b', 0), 'a b');22 t.end();23});2425test('(compat) should be trimmed', t => {26 t.is(fn('', 'b', {}, ''), 'b');27 t.end();28});2930test('(compat) returns an empty string for an empty configuration', t => {31 t.is(fn({}), '');32 t.end();33});3435test('(compat) supports an array of class names', t => {36 t.is(fn(['a', 'b']), 'a b');37 t.end();38});3940test('(compat) joins array arguments with string arguments', t => {41 t.is(fn(['a', 'b'], 'c'), 'a b c');42 t.is(fn('c', ['a', 'b']), 'c a b');43 t.end();44});4546test('(compat) handles multiple array arguments', t => {47 t.is(fn(['a', 'b'], ['c', 'd']), 'a b c d');48 t.end();49});5051test('(compat) handles arrays that include falsy and true values', t => {52 t.is(fn(['a', 0, null, undefined, false, true, 'b']), 'a b');53 t.end();54});5556test('(compat) handles arrays that include arrays', t => {57 t.is(fn(['a', ['b', 'c']]), 'a b c');58 t.end();59});6061test('(compat) handles arrays that include objects', t => {62 t.is(fn(['a', { b:true, c:false }]), 'a b');63 t.end();64});6566test('(compat) handles deep array recursion', t => {67 t.is(fn(['a', ['b', ['c', { d:true }]]]), 'a b c d');68 t.end();69});7071test('(compat) handles arrays that are empty', t => {72 t.is(fn('a', []), 'a');73 t.end();74});7576test('(compat) handles nested arrays that have empty nested arrays', t => {77 t.is(fn('a', [[]]), 'a');78 t.end();79});8081test('(compat) handles all types of truthy and falsy property values as expected', t => {82 const out = fn({83 // falsy:84 null: null,85 emptyString: '',86 noNumber: NaN,87 zero: 0,88 negativeZero: -0,89 false: false,90 undefined: undefined,9192 // truthy (literally anything else):93 nonEmptyString: 'foobar',94 whitespace: ' ',95 function: Object.prototype.toString,96 emptyObject: {},97 nonEmptyObject: {a: 1, b: 2},98 emptyList: [],99 nonEmptyList: [1, 2, 3],100 greaterZero: 1101 });102103 t.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');104 t.end();105});
added:test/index.js+65 added