|
1 | 1 | /** |
2 | 2 | * @license Apache-2.0 |
3 | 3 | * |
4 | | -* Copyright (c) 2019 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 objectKeys = require( '@stdlib/utils-keys' ); |
25 | | -var defineProperty = require( '@stdlib/utils-define-property' ); |
26 | | -var propertyDescriptor = require( '@stdlib/utils-property-descriptor' ); |
27 | | -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); |
28 | | -var setConfigurableWriteOnlyAccessor = require( './../../dist' ); // eslint-disable-line id-length |
| 24 | +var main = require( './../../dist' ); |
29 | 25 |
|
30 | 26 |
|
31 | 27 | // TESTS // |
32 | 28 |
|
33 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
34 | 30 | t.ok( true, __filename ); |
35 | | - t.strictEqual( typeof setConfigurableWriteOnlyAccessor, 'function', 'main export is a function' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
36 | 32 | t.end(); |
37 | 33 | }); |
38 | | - |
39 | | -tape( 'the function sets a property on a provided object', function test( t ) { |
40 | | - var obj = {}; |
41 | | - var val = ''; |
42 | | - |
43 | | - setConfigurableWriteOnlyAccessor( obj, 'foo', setter ); |
44 | | - obj.foo = 'bar'; |
45 | | - |
46 | | - t.equal( val, 'bar', 'equals expected value' ); |
47 | | - t.end(); |
48 | | - |
49 | | - function setter( v ) { |
50 | | - val = v; |
51 | | - } |
52 | | -}); |
53 | | - |
54 | | -tape( 'the write-only property is not readable', function test( t ) { |
55 | | - var obj = {}; |
56 | | - var val = ''; |
57 | | - |
58 | | - setConfigurableWriteOnlyAccessor( obj, 'foo', setter ); |
59 | | - t.equal( obj.foo, void 0, 'property cannot be get' ); |
60 | | - |
61 | | - t.equal( val, '', 'equals expected value' ); |
62 | | - t.end(); |
63 | | - |
64 | | - function setter(v ) { |
65 | | - val = v; |
66 | | - } |
67 | | -}); |
68 | | - |
69 | | -tape( 'the write-only property is not configurable', function test( t ) { |
70 | | - var desc; |
71 | | - var obj; |
72 | | - var val; |
73 | | - |
74 | | - val = ''; |
75 | | - |
76 | | - obj = {}; |
77 | | - setConfigurableWriteOnlyAccessor( obj, 'foo', setter ); |
78 | | - setConfigurableWriteOnlyAccessor( obj, 'beep', setter ); |
79 | | - |
80 | | - desc = { |
81 | | - 'configurable': true, |
82 | | - 'enumerable': false, |
83 | | - 'set': setter, |
84 | | - 'get': void 0 |
85 | | - }; |
86 | | - defineProperty( obj, 'foo', desc ); |
87 | | - t.deepEqual( propertyDescriptor( obj, 'foo' ), desc, 'property can be reconfigured' ); |
88 | | - |
89 | | - t.equal( hasOwnProp( obj, 'beep' ), true, 'has property' ); |
90 | | - |
91 | | - // Configurable properties can be deleted... |
92 | | - delete obj.beep; |
93 | | - t.equal( obj.beep, void 0, 'returns expected value' ); |
94 | | - t.equal( hasOwnProp( obj, 'beep' ), false, 'does not have property' ); |
95 | | - |
96 | | - t.equal( val, '', 'equals expected value' ); |
97 | | - t.end(); |
98 | | - |
99 | | - function setter( v ) { |
100 | | - val = v; |
101 | | - } |
102 | | -}); |
103 | | - |
104 | | -tape( 'the write-only property is enumerable', function test( t ) { |
105 | | - var obj = {}; |
106 | | - var val = ''; |
107 | | - |
108 | | - setConfigurableWriteOnlyAccessor( obj, 'foo', setter ); |
109 | | - t.deepEqual( objectKeys( obj ), [ 'foo' ], 'property is enumerable' ); |
110 | | - |
111 | | - t.equal( val, '', 'equals expected value' ); |
112 | | - t.end(); |
113 | | - |
114 | | - function setter( v ) { |
115 | | - val = v; |
116 | | - } |
117 | | -}); |
0 commit comments