index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. var test = require('tape');
  3. var isArguments = require('../');
  4. var hasToStringTag = require('has-tostringtag/shams')();
  5. test('primitives', function (t) {
  6. t.notOk(isArguments([]), 'array is not arguments');
  7. t.notOk(isArguments({}), 'object is not arguments');
  8. t.notOk(isArguments(''), 'empty string is not arguments');
  9. t.notOk(isArguments('foo'), 'string is not arguments');
  10. t.notOk(isArguments({ length: 2 }), 'naive array-like is not arguments');
  11. t.end();
  12. });
  13. test('arguments object', function (t) {
  14. t.ok(isArguments(arguments), 'arguments is arguments');
  15. t.notOk(isArguments(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments');
  16. t.end();
  17. });
  18. test('old-style arguments object', function (t) {
  19. var isLegacyArguments = isArguments.isLegacyArguments || isArguments;
  20. var fakeOldArguments = {
  21. callee: function () {},
  22. length: 3
  23. };
  24. t.ok(isLegacyArguments(fakeOldArguments), 'old-style arguments is arguments');
  25. t.end();
  26. });
  27. test('Symbol.toStringTag', { skip: !hasToStringTag }, function (t) {
  28. var obj = {};
  29. obj[Symbol.toStringTag] = 'Arguments';
  30. t.notOk(isArguments(obj), 'object with faked toStringTag is not arguments');
  31. var args = (function () {
  32. return arguments;
  33. }());
  34. args[Symbol.toStringTag] = 'Arguments';
  35. t.notOk(isArguments(obj), 'real arguments with faked toStringTag is not arguments');
  36. t.end();
  37. });