1 | 'use strict';
|
---|
2 |
|
---|
3 | var $defineProperty = require('../');
|
---|
4 |
|
---|
5 | var test = require('tape');
|
---|
6 | var gOPD = require('gopd');
|
---|
7 |
|
---|
8 | test('defineProperty: supported', { skip: !$defineProperty }, function (t) {
|
---|
9 | t.plan(4);
|
---|
10 |
|
---|
11 | t.equal(typeof $defineProperty, 'function', 'defineProperty is supported');
|
---|
12 | if ($defineProperty && gOPD) { // this `if` check is just to shut TS up
|
---|
13 | /** @type {{ a: number, b?: number, c?: number }} */
|
---|
14 | var o = { a: 1 };
|
---|
15 |
|
---|
16 | $defineProperty(o, 'b', { enumerable: true, value: 2 });
|
---|
17 | t.deepEqual(
|
---|
18 | gOPD(o, 'b'),
|
---|
19 | {
|
---|
20 | configurable: false,
|
---|
21 | enumerable: true,
|
---|
22 | value: 2,
|
---|
23 | writable: false
|
---|
24 | },
|
---|
25 | 'property descriptor is as expected'
|
---|
26 | );
|
---|
27 |
|
---|
28 | $defineProperty(o, 'c', { enumerable: false, value: 3, writable: true });
|
---|
29 | t.deepEqual(
|
---|
30 | gOPD(o, 'c'),
|
---|
31 | {
|
---|
32 | configurable: false,
|
---|
33 | enumerable: false,
|
---|
34 | value: 3,
|
---|
35 | writable: true
|
---|
36 | },
|
---|
37 | 'property descriptor is as expected'
|
---|
38 | );
|
---|
39 | }
|
---|
40 |
|
---|
41 | t.equal($defineProperty, Object.defineProperty, 'defineProperty is Object.defineProperty');
|
---|
42 |
|
---|
43 | t.end();
|
---|
44 | });
|
---|
45 |
|
---|
46 | test('defineProperty: not supported', { skip: !!$defineProperty }, function (t) {
|
---|
47 | t.notOk($defineProperty, 'defineProperty is not supported');
|
---|
48 |
|
---|
49 | t.match(
|
---|
50 | typeof $defineProperty,
|
---|
51 | /^(?:undefined|boolean)$/,
|
---|
52 | '`typeof defineProperty` is `undefined` or `boolean`'
|
---|
53 | );
|
---|
54 |
|
---|
55 | t.end();
|
---|
56 | });
|
---|