CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
set.js51 linesDownload Raw Back to test
1'use strict';2 3var test = require('tape');4 5var setDunderProto = require('../set');6 7test('setDunderProto', { skip: !setDunderProto }, function (t) {8	if (!setDunderProto) {9		throw 'should never happen; this is just for type narrowing'; // eslint-disable-line no-throw-literal10	}11 12	// @ts-expect-error13	t['throws'](function () { setDunderProto(); }, TypeError, 'throws if no arguments');14	// @ts-expect-error15	t['throws'](function () { setDunderProto(undefined); }, TypeError, 'throws with undefined and nothing');16	// @ts-expect-error17	t['throws'](function () { setDunderProto(undefined, undefined); }, TypeError, 'throws with undefined and undefined');18	// @ts-expect-error19	t['throws'](function () { setDunderProto(null); }, TypeError, 'throws with null and undefined');20	// @ts-expect-error21	t['throws'](function () { setDunderProto(null, undefined); }, TypeError, 'throws with null and undefined');22 23	/** @type {{ inherited?: boolean }} */24	var obj = {};25	t.ok('toString' in obj, 'object initially has toString');26 27	setDunderProto(obj, null);28	t.notOk('toString' in obj, 'object no longer has toString');29 30	t.notOk('inherited' in obj, 'object lacks inherited property');31	setDunderProto(obj, { inherited: true });32	t.equal(obj.inherited, true, 'object has inherited property');33 34	t.end();35});36 37test('no dunder proto', { skip: !!setDunderProto }, function (t) {38	if ('__proto__' in Object.prototype) {39		t['throws'](40			// @ts-expect-error41			function () { ({}).__proto__ = null; }, // eslint-disable-line no-proto42			Error,43			'throws when setting Object.prototype.__proto__'44		);45	} else {46		t.notOk('__proto__' in Object.prototype, 'no __proto__ in Object.prototype');47	}48 49	t.end();50});51