utils.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { utils } from '../www/index-ios';
  2. import assert from 'assert';
  3. describe('utils', () => {
  4. describe('#chunk', () => {
  5. it('should chunk a given array', () => {
  6. const chunks = utils.chunk(['1', '2', '3', '4', '5'], 2);
  7. assert.deepEqual(chunks, [['1', '2'], ['3', '4'], ['5']]);
  8. });
  9. it('should return on chunk when the size is bigger than the array size', () => {
  10. const chunks = utils.chunk(['1', '2', '3', '4', '5'], 42);
  11. assert.deepEqual(chunks, [['1', '2', '3', '4', '5']]);
  12. });
  13. it('should throw an error on size smaller 1', () => {
  14. assert.throws(() => {
  15. utils.chunk(['1', '2', '3', '4', '5'], 0);
  16. }, (err) => {
  17. return err.message === 'Invalid size';
  18. }, 'unexpected error');
  19. });
  20. it('should throw an error on non numeric size', () => {
  21. assert.throws(() => {
  22. utils.chunk(['1', '2', '3', '4', '5'], 'not a number');
  23. }, (err) => {
  24. return err.message === 'Invalid size';
  25. }, 'unexpected error');
  26. });
  27. it('should throw an error when on a non array type', () => {
  28. assert.throws(() => {
  29. utils.chunk(null, 2);
  30. }, (err) => {
  31. return err.message === 'Invalid array';
  32. }, 'unexpected error');
  33. });
  34. });
  35. });