|
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 objectKeys = require( '@stdlib/utils-keys' ); |
25 | | -var defineProperty = require( '@stdlib/utils-define-property' ); |
26 | | -var setWriteOnlyAccessor = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
27 | 25 |
|
28 | 26 |
|
29 | 27 | // TESTS // |
30 | 28 |
|
31 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
32 | 30 | t.ok( true, __filename ); |
33 | | - t.strictEqual( typeof setWriteOnlyAccessor, 'function', 'main export is a function' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
34 | 32 | t.end(); |
35 | 33 | }); |
36 | | - |
37 | | -tape( 'the function sets a property on a provided object', function test( t ) { |
38 | | - var obj = {}; |
39 | | - var val = ''; |
40 | | - |
41 | | - setWriteOnlyAccessor( obj, 'foo', setter ); |
42 | | - obj.foo = 'bar'; |
43 | | - |
44 | | - t.equal( val, 'bar', 'equals expected value' ); |
45 | | - t.end(); |
46 | | - |
47 | | - function setter( v ) { |
48 | | - val = v; |
49 | | - } |
50 | | -}); |
51 | | - |
52 | | -tape( 'the write-only property is not readable', function test( t ) { |
53 | | - var obj = {}; |
54 | | - var val = ''; |
55 | | - |
56 | | - setWriteOnlyAccessor( obj, 'foo', setter ); |
57 | | - t.equal( obj.foo, void 0, 'property cannot be get' ); |
58 | | - |
59 | | - t.equal( val, '', 'equals expected value' ); |
60 | | - t.end(); |
61 | | - |
62 | | - function setter(v ) { |
63 | | - val = v; |
64 | | - } |
65 | | -}); |
66 | | - |
67 | | -tape( 'the write-only property is not configurable', function test( t ) { |
68 | | - var obj = {}; |
69 | | - var val = ''; |
70 | | - |
71 | | - setWriteOnlyAccessor( obj, 'foo', setter ); |
72 | | - t.throws( foo, Error, 'property cannot be deleted' ); |
73 | | - t.throws( bar, Error, 'property cannot be reconfigured' ); |
74 | | - |
75 | | - t.equal( val, '', 'equals expected value' ); |
76 | | - t.end(); |
77 | | - |
78 | | - function setter( v ) { |
79 | | - val = v; |
80 | | - } |
81 | | - |
82 | | - function foo() { |
83 | | - delete obj.foo; |
84 | | - } |
85 | | - |
86 | | - function bar() { |
87 | | - defineProperty( obj, 'foo', { |
88 | | - 'value': 'boop', |
89 | | - 'writable': true, |
90 | | - 'configurable': false, |
91 | | - 'enumerable': true |
92 | | - }); |
93 | | - } |
94 | | -}); |
95 | | - |
96 | | -tape( 'the write-only property is enumerable', function test( t ) { |
97 | | - var obj = {}; |
98 | | - var val = ''; |
99 | | - |
100 | | - setWriteOnlyAccessor( obj, 'foo', setter ); |
101 | | - t.equal( objectKeys( obj )[ 0 ], 'foo', 'property is enumerable' ); |
102 | | - |
103 | | - t.equal( val, '', 'equals expected value' ); |
104 | | - t.end(); |
105 | | - |
106 | | - function setter( v ) { |
107 | | - val = v; |
108 | | - } |
109 | | -}); |
0 commit comments