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
Provenance
- Commit
25fcd73- Tree
6f361f7- Author
Luke Edwards <luke.edwards05@gmail.com>- Committer
Luke Edwards <luke.edwards05@gmail.com>- Parent
30520d3
2 files changed+170 added−0 removed
added:test/classnames.js+105 added
1+/**2+ * Ported from `classnames` for compatibility checks.3+ */4+5+const test = require('tape');6+const fn = require('../dist/clsx');7+8+test('(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+});13+14+test('(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+});19+20+test('(compat) supports heterogenous arguments', t => {21+ t.is(fn({ a:true }, 'b', 0), 'a b');22+ t.end();23+});24+25+test('(compat) should be trimmed', t => {26+ t.is(fn('', 'b', {}, ''), 'b');27+ t.end();28+});29+30+test('(compat) returns an empty string for an empty configuration', t => {31+ t.is(fn({}), '');32+ t.end();33+});34+35+test('(compat) supports an array of class names', t => {36+ t.is(fn(['a', 'b']), 'a b');37+ t.end();38+});39+40+test('(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+});45+46+test('(compat) handles multiple array arguments', t => {47+ t.is(fn(['a', 'b'], ['c', 'd']), 'a b c d');48+ t.end();49+});50+51+test('(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+});55+56+test('(compat) handles arrays that include arrays', t => {57+ t.is(fn(['a', ['b', 'c']]), 'a b c');58+ t.end();59+});60+61+test('(compat) handles arrays that include objects', t => {62+ t.is(fn(['a', { b:true, c:false }]), 'a b');63+ t.end();64+});65+66+test('(compat) handles deep array recursion', t => {67+ t.is(fn(['a', ['b', ['c', { d:true }]]]), 'a b c d');68+ t.end();69+});70+71+test('(compat) handles arrays that are empty', t => {72+ t.is(fn('a', []), 'a');73+ t.end();74+});75+76+test('(compat) handles nested arrays that have empty nested arrays', t => {77+ t.is(fn('a', [[]]), 'a');78+ t.end();79+});80+81+test('(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,91+92+ // 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+ });102+103+ t.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');104+ t.end();105+});added:test/index.js+65 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465const test = require('tape');const fn = require('../dist/clsx');
test('clsx', t => { t.is(typeof fn, 'function', 'exports a function'); t.is(typeof fn(), 'string', '~> returns string output'); t.end();});
test('strings', t => { t.is(fn(''), ''); t.is(fn('foo'), 'foo'); t.is(fn(true && 'foo'), 'foo'); t.is(fn(false && 'foo'), ''); t.end();});
test('strings (variadic)', t => { t.is(fn(''), ''); t.is(fn('foo'), 'foo'); t.is(fn(true && 'foo'), 'foo'); t.is(fn(false && 'foo'), ''); t.end();});
test('objects', t => { t.is(fn({}), ''); t.is(fn({ foo:true }), 'foo'); t.is(fn({ foo:true, bar:false }), 'foo'); t.is(fn({ foo:'hiya', bar:1 }), 'foo bar'); t.is(fn({ foo:1, bar:0, baz:1 }), 'foo baz'); t.is(fn({ '-foo':1, '--bar':1 }), '-foo --bar'); t.end();});
test('objects (variadic)', t => { t.is(fn({}, {}), ''); t.is(fn({ foo:1 }, { bar:2 }), 'foo bar'); t.is(fn({ foo:1 }, null, { baz:1, bat:0 }), 'foo baz'); t.is(fn({ foo:1 }, {}, {}, { bar:'a' }, { baz:null, bat:Infinity }), 'foo bar bat'); t.end();});
test('arrays', t => { t.is(fn([]), ''); t.is(fn(['foo']), 'foo'); t.is(fn(['foo', 'bar']), 'foo bar'); t.is(fn(['foo', 0 && 'bar', 1 && 'baz']), 'foo baz'); t.end();});
test('arrays (nested)', t => { t.is(fn([[[]]]), ''); t.is(fn([[['foo']]]), 'foo'); t.is(fn([true, [['foo']]]), 'foo');; t.is(fn(['foo', ['bar', ['', [['baz']]]]]), 'foo bar baz'); t.end();});
test('arrays (variadic)', t => { t.is(fn([], []), ''); t.is(fn(['foo'], ['bar']), 'foo bar'); t.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz'); t.end();});