1 | 'use strict';
|
---|
2 |
|
---|
3 | var test = require('tape');
|
---|
4 |
|
---|
5 | var setProto = require('../');
|
---|
6 |
|
---|
7 | var isPrototypeOf = Object.prototype.isPrototypeOf;
|
---|
8 |
|
---|
9 | test('setProto', function (t) {
|
---|
10 | t.equal(typeof setProto, 'function', 'is a function');
|
---|
11 |
|
---|
12 | t.test('can set', { skip: !setProto }, function (st) {
|
---|
13 | var obj = { a: 1 };
|
---|
14 | var proto = { b: 2 };
|
---|
15 |
|
---|
16 | st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
|
---|
17 | st.notOk(isPrototypeOf.call(proto, obj), 'proto is not isPrototypeOf obj');
|
---|
18 | st.ok('a' in obj, 'a is in obj');
|
---|
19 | st.notOk('b' in obj, 'b is not in obj');
|
---|
20 |
|
---|
21 | // eslint-disable-next-line no-extra-parens
|
---|
22 | st.equal(/** @type {NonNullable<typeof setProto>} */ (setProto)(obj, proto), obj, 'returns the object');
|
---|
23 |
|
---|
24 | st.ok(isPrototypeOf.call(Object.prototype, obj), 'Object.prototype is isPrototypeOf obj');
|
---|
25 | st.ok(isPrototypeOf.call(proto, obj), 'proto is isPrototypeOf obj');
|
---|
26 | st.ok('a' in obj, 'a is in obj');
|
---|
27 | st.ok('b' in obj, 'b is in obj');
|
---|
28 |
|
---|
29 | st.equal(Object.getPrototypeOf(obj), proto, 'sets the prototype');
|
---|
30 | st.end();
|
---|
31 | });
|
---|
32 |
|
---|
33 | t.test('can not set', { skip: !!setProto }, function (st) {
|
---|
34 | st.equal(setProto, null);
|
---|
35 |
|
---|
36 | st.end();
|
---|
37 | });
|
---|
38 |
|
---|
39 | t.end();
|
---|
40 | });
|
---|