-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
52 lines (39 loc) · 1.61 KB
/
solution.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
42
43
44
45
46
47
48
49
50
51
52
// 60: Reflect - getPrototypeOf (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Reflect.getPrototypeOf` returns the prototype', function() {
it('works like `Object.getPrototypeOf`', function() {
const viaObject = Object.getPrototypeOf({});
const viaReflect = Reflect.getPrototypeOf({});
assert.strictEqual(viaObject, viaReflect);
});
it('throws a TypeError for a non-object', function() {
let fn = () => { Reflect.getPrototypeOf() };
assert.throws(fn, TypeError);
});
it('a `new Set()` has a prototype', function() {
const aSet = new Set();
assert.equal(Reflect.getPrototypeOf(aSet), Set.prototype);
});
it('for a class, it is `Klass.prototype`', function() {
class Klass {}
const proto = Reflect.getPrototypeOf(new Klass());
assert.equal(proto, Klass.prototype);
});
it('for a old-style class, works too', function() {
function Klass() {}
const proto = Reflect.getPrototypeOf(new Klass());
assert.equal(proto, Klass.prototype);
});
it('an array has a prototype too', function() {
let arr = [];
const expectedProto = Array.prototype;
assert.equal(Reflect.getPrototypeOf(arr), expectedProto);
});
// TODO
// it('getting the prototype of an "exotic namespace object" returns `null`', function() {
// http://www.ecma-international.org/ecma-262/6.0/#sec-module-namespace-exotic-objects-getprototypeof
// Don't know how to write a test for this yet, without creating a dep in tddbin hardcoded
// PRs welcome
// assert.equal(Reflect.getPrototypeOf(namespace exotic object), null);
// });
});