Skip to content

High performance self-hosted photo and video management solution.

1.1 KB
Raw Blame
import { cleanClass, isDefined } from '#lib';

describe('cleanClass', () => {
  it('should return a string of class names', () => {
    expect(cleanClass('class1', 'class2', 'class3')).toBe('class1 class2 class3');
  });

  it('should filter out undefined, null, and false values', () => {
    expect(cleanClass('class1', undefined, 'class2', null, 'class3', false)).toBe('class1 class2 class3');
  });

  it('should unnest arrays', () => {
    expect(cleanClass('class1', ['class2', 'class3'])).toBe('class1 class2 class3');
  });

  it('should unnest doubly nested arrays', () => {
    expect(cleanClass('class1', [['class2a', 'class2b'], 'class3'])).toBe('class1 class2a class2b class3');
  });
});

describe('isDefined', () => {
  it('should return false for null', () => {
    expect(isDefined(null)).toBe(false);
  });

  it('should return false for undefined', () => {
    expect(isDefined(undefined)).toBe(false);
  });

  it('should return true for everything else', () => {
    for (const value of [0, 1, 2, true, false, {}, 'foo', 'bar', []]) {
      expect(isDefined(value)).toBe(true);
    }
  });
});