/
es.object.define-property.js
32 lines (28 loc) · 1.07 KB
/
es.object.define-property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { DESCRIPTORS } from '../helpers/constants';
QUnit.test('Object.defineProperty', assert => {
const { defineProperty, create } = Object;
assert.isFunction(defineProperty);
assert.arity(defineProperty, 3);
assert.name(defineProperty, 'defineProperty');
assert.looksNative(defineProperty);
assert.nonEnumerable(Object, 'defineProperty');
const source = {};
const result = defineProperty(source, 'q', {
value: 42,
});
assert.same(result, source);
assert.same(result.q, 42);
if (DESCRIPTORS) {
// eslint-disable-next-line prefer-arrow-callback -- required for testing
assert.same(defineProperty(function () { /* empty */ }, 'prototype', {
value: 42,
writable: false,
}).prototype, 42, 'function prototype with non-writable descriptor');
}
assert.throws(() => defineProperty(42, 1, {}));
assert.throws(() => defineProperty({}, create(null), {}));
assert.throws(() => defineProperty({}, 1, 1));
});
QUnit.test('Object.defineProperty.sham flag', assert => {
assert.same(Object.defineProperty.sham, DESCRIPTORS ? undefined : true);
});