array.test.js 992 B

12345678910111213141516171819202122232425
  1. import { removeFromArray, removeIfMatchPattern, toArray, toChunks, } from '../array.js';
  2. describe('next-sitemap/array', () => {
  3. test('toChunks', () => {
  4. const inputArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  5. const chunkSize = 3;
  6. const chunks = toChunks(inputArray, chunkSize);
  7. expect(chunks).toStrictEqual([
  8. [0, 1, 2],
  9. [3, 4, 5],
  10. [6, 7, 8],
  11. [9, 10],
  12. ]);
  13. });
  14. test('toArray', () => {
  15. expect(toArray('hello')).toStrictEqual(['hello']);
  16. expect(toArray(['hello', 'world'])).toStrictEqual(['hello', 'world']);
  17. });
  18. test('removeFromArray', () => {
  19. expect(removeFromArray([1, 2, 3], [2])).toStrictEqual([1, 3]);
  20. expect(removeFromArray([1, 2, 3], [2, 3, 4])).toStrictEqual([1]);
  21. });
  22. test('removeIfMatchPattern', () => {
  23. expect(removeIfMatchPattern(['/hello', '/world', '/something'], ['/hello*', '/som*'])).toStrictEqual(['/world']);
  24. });
  25. });