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