|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var defineProperty = require( '@stdlib/utils-define-property' ); |
25 |
| -var isDataPropertyIn = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
26 | 25 |
|
27 | 26 |
|
28 | 27 | // TESTS //
|
29 | 28 |
|
30 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
31 | 30 | t.ok( true, __filename );
|
32 |
| - t.strictEqual( typeof isDataPropertyIn, 'function', 'export is a function' ); |
33 |
| - t.end(); |
34 |
| -}); |
35 |
| - |
36 |
| -tape( 'the function returns `true` if an object property has a data descriptor', function test( t ) { |
37 |
| - var bool; |
38 |
| - var obj; |
39 |
| - |
40 |
| - function Foo() { |
41 |
| - this.bar = 'beep'; |
42 |
| - return this; |
43 |
| - } |
44 |
| - |
45 |
| - obj = { |
46 |
| - 'a': 'b' |
47 |
| - }; |
48 |
| - bool = isDataPropertyIn( obj, 'a' ); |
49 |
| - t.equal( bool, true, 'returns true' ); |
50 |
| - |
51 |
| - bool = isDataPropertyIn( [ 1, 2, 3 ], '1' ); |
52 |
| - t.equal( bool, true, 'returns true' ); |
53 |
| - |
54 |
| - bool = isDataPropertyIn( [ 1, 2, 3 ], 1 ); |
55 |
| - t.equal( bool, true, 'returns true' ); |
56 |
| - |
57 |
| - bool = isDataPropertyIn( new Foo(), 'bar' ); |
58 |
| - t.equal( bool, true, 'returns true' ); |
59 |
| - |
60 |
| - bool = isDataPropertyIn( [ 'a' ], 'length' ); |
61 |
| - t.equal( bool, true, 'returns true' ); |
62 |
| - |
63 |
| - obj = {}; |
64 |
| - defineProperty( obj, 'a', { |
65 |
| - 'configurable': false, |
66 |
| - 'enumerable': false, |
67 |
| - 'writable': true, |
68 |
| - 'value': 'b' |
69 |
| - }); |
70 |
| - |
71 |
| - bool = isDataPropertyIn( obj, 'a' ); |
72 |
| - t.equal( bool, true, 'returns true' ); |
73 |
| - |
74 |
| - t.end(); |
75 |
| -}); |
76 |
| - |
77 |
| -tape( 'the function returns `false` if provided `null` or `undefined` for the first argument', function test( t ) { |
78 |
| - var bool; |
79 |
| - |
80 |
| - bool = isDataPropertyIn( null, 'beep' ); |
81 |
| - t.equal( bool, false, 'returns false when provided null' ); |
82 |
| - |
83 |
| - bool = isDataPropertyIn( void 0, 'beep' ); |
84 |
| - t.equal( bool, false, 'returns false when provided undefined' ); |
85 |
| - |
86 |
| - t.end(); |
87 |
| -}); |
88 |
| - |
89 |
| -tape( 'the function returns `false` if provided a property argument which does not correspond to a property having a data descriptor', function test( t ) { |
90 |
| - var bool; |
91 |
| - var obj; |
92 |
| - |
93 |
| - obj = { |
94 |
| - 'a': 'b' |
95 |
| - }; |
96 |
| - |
97 |
| - bool = isDataPropertyIn( obj, 'c' ); |
98 |
| - t.equal( bool, false, 'returns false' ); |
99 |
| - |
100 |
| - obj = {}; |
101 |
| - defineProperty( obj, 'a', { |
102 |
| - 'configurable': false, |
103 |
| - 'enumerable': false, |
104 |
| - 'get': getter, |
105 |
| - 'set': setter |
106 |
| - }); |
107 |
| - |
108 |
| - bool = isDataPropertyIn( obj, 'a' ); |
109 |
| - t.equal( bool, false, 'returns false' ); |
110 |
| - |
111 |
| - t.end(); |
112 |
| - |
113 |
| - function getter() { |
114 |
| - // No-op... |
115 |
| - } |
116 |
| - |
117 |
| - function setter() { |
118 |
| - // No-op... |
119 |
| - } |
120 |
| -}); |
121 |
| - |
122 |
| -tape( 'the function returns `true` if provided an inherited property having a data descriptor', function test( t ) { |
123 |
| - var bool; |
124 |
| - |
125 |
| - bool = isDataPropertyIn( {}, 'hasOwnProperty' ); |
126 |
| - t.equal( bool, true, 'returns true' ); |
127 |
| - |
128 |
| - bool = isDataPropertyIn( {}, 'toString' ); |
129 |
| - t.equal( bool, true, 'returns true' ); |
130 |
| - |
131 |
| - bool = isDataPropertyIn( {}, 'constructor' ); |
132 |
| - t.equal( bool, true, 'returns true' ); |
133 |
| - |
134 |
| - t.end(); |
135 |
| -}); |
136 |
| - |
137 |
| -tape( 'the function returns `false` if provided an inherited property not having a data descriptor', function test( t ) { |
138 |
| - var bool; |
139 |
| - var obj; |
140 |
| - |
141 |
| - function Foo() { |
142 |
| - return this; |
143 |
| - } |
144 |
| - |
145 |
| - defineProperty( Foo.prototype, 'bar', { |
146 |
| - 'configurable': true, |
147 |
| - 'enumerable': true, |
148 |
| - 'get': getter, |
149 |
| - 'set': setter |
150 |
| - }); |
151 |
| - |
152 |
| - obj = new Foo(); |
153 |
| - |
154 |
| - bool = isDataPropertyIn( obj, 'bar' ); |
155 |
| - t.equal( bool, false, 'returns false' ); |
156 |
| - |
157 |
| - t.end(); |
158 |
| - |
159 |
| - function getter() { |
160 |
| - // No-op... |
161 |
| - } |
162 |
| - |
163 |
| - function setter() { |
164 |
| - // No-op... |
165 |
| - } |
166 |
| -}); |
167 |
| - |
168 |
| -tape( 'values are coerced to objects', function test( t ) { |
169 |
| - var bool; |
170 |
| - |
171 |
| - bool = isDataPropertyIn( 'beep', 'length' ); |
172 |
| - t.equal( bool, true, 'returns true' ); |
173 |
| - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
174 | 32 | t.end();
|
175 | 33 | });
|
0 commit comments