Debian Codegraph @

hasown/test/index.js

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 'use strict';
2
3 var test = require('tape');
•4 //var mockProperty = require('mock-property');
5
6 var hasOwn = require('../');
7
8 test('hasOwn', function (t) {
9 t.equal(typeof hasOwn, 'function', 'is a function');
10
11 t.equal(
12 hasOwn({}, 'toString'),
13 false,
14 'toString is not an own property of a normal object'
15 );
16
17 t.equal(
18 hasOwn({ toString: true }, 'toString'),
19 true,
20 'toString as an own property is an own property'
21 );
22
23 t.equal(
24 hasOwn({ a: true }, 'a'),
25 true,
26 'a normal own property is an own property'
27 );
28
29 t.equal(hasOwn([], 'length'), true, 'an array length is an own property');
30 t.equal(hasOwn('', 'length'), true, 'a string length is an own property');
31
32 t.test('without a `.call`', function (st) {
•33 // var restore = mockProperty(Function.prototype, 'call', { 'delete': true });
34 // st.teardown(restore);
35
36 var toS = hasOwn({ toString: true }, 'toString');
37 var ownA = hasOwn({ a: true }, 'a');
38 var arrL = hasOwn([], 'length');
39 var strL = hasOwn('', 'length');
40
41 // TODO: remove this line once node is fixed
•42 // restore();
43
44 st.equal(toS, true, 'no call; toString as an own property is an own property');
45 st.equal(ownA, true, 'no call; a normal own property is an own property');
46 st.equal(arrL, true, 'no call; an array length is an own property');
47 st.equal(strL, true, 'no call; a string length is an own property');
48
49 st.end();
50 });
51
52 t.end();
53 });