forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.reflect.define-property.js
41 lines (38 loc) · 1.3 KB
/
es.reflect.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
33
34
35
36
37
38
39
40
41
import { DESCRIPTORS } from '../helpers/constants';
import defineProperty from 'core-js-pure/features/reflect/define-property';
import { getOwnPropertyDescriptor, create } from 'core-js-pure/features/object';
QUnit.test('Reflect.defineProperty', assert => {
assert.isFunction(defineProperty);
assert.arity(defineProperty, 3);
if ('name' in defineProperty) {
assert.name(defineProperty, 'defineProperty');
}
let object = {};
assert.strictEqual(defineProperty(object, 'foo', { value: 123 }), true);
assert.strictEqual(object.foo, 123);
if (DESCRIPTORS) {
object = {};
defineProperty(object, 'foo', {
value: 123,
enumerable: true,
});
assert.deepEqual(getOwnPropertyDescriptor(object, 'foo'), {
value: 123,
enumerable: true,
configurable: false,
writable: false,
});
assert.strictEqual(defineProperty(object, 'foo', {
value: 42,
}), false);
}
assert.throws(() => defineProperty(42, 'foo', {
value: 42,
}), TypeError, 'throws on primitive');
assert.throws(() => defineProperty(42, 1, {}));
assert.throws(() => defineProperty({}, create(null), {}));
assert.throws(() => defineProperty({}, 1, 1));
});
QUnit.test('Reflect.defineProperty.sham flag', assert => {
assert.same(defineProperty.sham, DESCRIPTORS ? undefined : true);
});