index.js 730 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var test = require('tape');
  3. var safePushApply = require('../');
  4. test('safe-push-apply', function (t) {
  5. t.equal(typeof safePushApply, 'function', 'is a function');
  6. t.equal(safePushApply.length, 2, 'has a length of 2');
  7. t['throws'](
  8. // @ts-expect-error
  9. function () { safePushApply({}, []); },
  10. TypeError,
  11. 'throws if target is not an array'
  12. );
  13. var a = [1, 2];
  14. var b = [3, 4];
  15. safePushApply(a, b);
  16. t.deepEqual(a, [1, 2, 3, 4], 'b is pushed into a');
  17. t.deepEqual(b, [3, 4], 'b is not modified');
  18. var c = '567';
  19. // @ts-expect-error TS ArrayLike doesn't accept strings for some reason
  20. safePushApply(a, c);
  21. t.deepEqual(a, [1, 2, 3, 4, '5', '6', '7'], 'works with arraylike source');
  22. t.end();
  23. });