to-camel-case.spec.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import {expect} from 'chai';
  2. import {format} from '@e22m4u/js-format';
  3. import {toCamelCase} from './to-camel-case.js';
  4. describe('toCamelCase', function () {
  5. it('requires the first parameter to be a String', function () {
  6. const throwable = v => () => toCamelCase(v);
  7. const error = v =>
  8. format(
  9. 'The first argument of "toCamelCase" ' +
  10. 'should be a String, but %s was given.',
  11. v,
  12. );
  13. expect(throwable(10)).to.throw(error('10'));
  14. expect(throwable(0)).to.throw(error('0'));
  15. expect(throwable(true)).to.throw(error('true'));
  16. expect(throwable(false)).to.throw(error('false'));
  17. expect(throwable(null)).to.throw(error('null'));
  18. expect(throwable({})).to.throw(error('Object'));
  19. expect(throwable([])).to.throw(error('Array'));
  20. expect(throwable(undefined)).to.throw(error('undefined'));
  21. throwable('str')();
  22. throwable('')();
  23. });
  24. it('returns a camelCase string', function () {
  25. expect(toCamelCase('TestString')).to.be.eq('testString');
  26. expect(toCamelCase('test-string')).to.be.eq('testString');
  27. expect(toCamelCase('test string')).to.be.eq('testString');
  28. expect(toCamelCase('Test string')).to.be.eq('testString');
  29. });
  30. });