AK-21/Graphite-Industrial-Intelligence
0
1'use strict';2 3var test = require('tape');4 5var getProto = require('../');6 7test('getProto', function (t) {8 t.equal(typeof getProto, 'function', 'is a function');9 10 t.test('can get', { skip: !getProto }, function (st) {11 if (getProto) { // TS doesn't understand tape's skip12 var proto = { b: 2 };13 st.equal(getProto(proto), Object.prototype, 'proto: returns the [[Prototype]]');14 15 st.test('nullish value', function (s2t) {16 // @ts-expect-error17 s2t['throws'](function () { return getProto(undefined); }, TypeError, 'undefined is not an object');18 // @ts-expect-error19 s2t['throws'](function () { return getProto(null); }, TypeError, 'null is not an object');20 s2t.end();21 });22 23 // @ts-expect-error24 st['throws'](function () { getProto(true); }, 'throws for true');25 // @ts-expect-error26 st['throws'](function () { getProto(false); }, 'throws for false');27 // @ts-expect-error28 st['throws'](function () { getProto(42); }, 'throws for 42');29 // @ts-expect-error30 st['throws'](function () { getProto(NaN); }, 'throws for NaN');31 // @ts-expect-error32 st['throws'](function () { getProto(0); }, 'throws for +0');33 // @ts-expect-error34 st['throws'](function () { getProto(-0); }, 'throws for -0');35 // @ts-expect-error36 st['throws'](function () { getProto(Infinity); }, 'throws for ∞');37 // @ts-expect-error38 st['throws'](function () { getProto(-Infinity); }, 'throws for -∞');39 // @ts-expect-error40 st['throws'](function () { getProto(''); }, 'throws for empty string');41 // @ts-expect-error42 st['throws'](function () { getProto('foo'); }, 'throws for non-empty string');43 st.equal(getProto(/a/g), RegExp.prototype);44 st.equal(getProto(new Date()), Date.prototype);45 st.equal(getProto(function () {}), Function.prototype);46 st.equal(getProto([]), Array.prototype);47 st.equal(getProto({}), Object.prototype);48 49 var nullObject = { __proto__: null };50 if ('toString' in nullObject) {51 st.comment('no null objects in this engine');52 st.equal(getProto(nullObject), Object.prototype, '"null" object has Object.prototype as [[Prototype]]');53 } else {54 st.equal(getProto(nullObject), null, 'null object has null [[Prototype]]');55 }56 }57 58 st.end();59 });60 61 t.test('can not get', { skip: !!getProto }, function (st) {62 st.equal(getProto, null);63 64 st.end();65 });66 67 t.end();68});69 