forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.object.create.js
34 lines (31 loc) · 1.12 KB
/
es.object.create.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
import { DESCRIPTORS } from '../helpers/constants';
import { create, getPrototypeOf, getOwnPropertyNames } from 'core-js-pure/features/object';
QUnit.test('Object.create', assert => {
function getPropertyNames(object) {
let result = [];
do {
result = result.concat(getOwnPropertyNames(object));
} while (object = getPrototypeOf(object));
return result;
}
assert.isFunction(create);
assert.arity(create, 2);
let object = { q: 1 };
assert.ok({}.isPrototypeOf.call(object, create(object)));
assert.ok(create(object).q === 1);
function C() {
return this.a = 1;
}
assert.ok(create(new C()) instanceof C);
assert.ok(C.prototype === getPrototypeOf(getPrototypeOf(create(new C()))));
assert.ok(create(new C()).a === 1);
assert.ok(create({}, { a: { value: 42 } }).a === 42);
object = create(null, { w: { value: 2 } });
assert.same(object, Object(object));
assert.ok(!('toString' in object));
assert.ok(object.w === 2);
assert.deepEqual(getPropertyNames(create(null)), []);
});
QUnit.test('Object.create.sham flag', assert => {
assert.same(create.sham, DESCRIPTORS ? undefined : true);
});