CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
index.js64 linesDownload Raw Back to test
1'use strict';2 3var callBind = require('../');4var hasStrictMode = require('has-strict-mode')();5var forEach = require('for-each');6var inspect = require('object-inspect');7var v = require('es-value-fixtures');8 9var test = require('tape');10 11test('callBindBasic', function (t) {12	forEach(v.nonFunctions, function (nonFunction) {13		t['throws'](14			// @ts-expect-error15			function () { callBind([nonFunction]); },16			TypeError,17			inspect(nonFunction) + ' is not a function'18		);19	});20 21	var sentinel = { sentinel: true };22	/** @type {<T, A extends number, B extends number>(this: T, a: A, b: B) => [T | undefined, A, B]} */23	var func = function (a, b) {24		// eslint-disable-next-line no-invalid-this25		return [!hasStrictMode && this === global ? undefined : this, a, b];26	};27	t.equal(func.length, 2, 'original function length is 2');28 29	/** type {(thisArg: unknown, a: number, b: number) => [unknown, number, number]} */30	var bound = callBind([func]);31	/** type {((a: number, b: number) => [typeof sentinel, typeof a, typeof b])} */32	var boundR = callBind([func, sentinel]);33	/** type {((b: number) => [typeof sentinel, number, typeof b])} */34	var boundArg = callBind([func, sentinel, /** @type {const} */ (1)]);35 36	// @ts-expect-error37	t.deepEqual(bound(), [undefined, undefined, undefined], 'bound func with no args');38 39	// @ts-expect-error40	t.deepEqual(func(), [undefined, undefined, undefined], 'unbound func with too few args');41	// @ts-expect-error42	t.deepEqual(bound(1, 2), [hasStrictMode ? 1 : Object(1), 2, undefined], 'bound func too few args');43	// @ts-expect-error44	t.deepEqual(boundR(), [sentinel, undefined, undefined], 'bound func with receiver, with too few args');45	// @ts-expect-error46	t.deepEqual(boundArg(), [sentinel, 1, undefined], 'bound func with receiver and arg, with too few args');47 48	t.deepEqual(func(1, 2), [undefined, 1, 2], 'unbound func with right args');49	t.deepEqual(bound(1, 2, 3), [hasStrictMode ? 1 : Object(1), 2, 3], 'bound func with right args');50	t.deepEqual(boundR(1, 2), [sentinel, 1, 2], 'bound func with receiver, with right args');51	t.deepEqual(boundArg(2), [sentinel, 1, 2], 'bound func with receiver and arg, with right arg');52 53	// @ts-expect-error54	t.deepEqual(func(1, 2, 3), [undefined, 1, 2], 'unbound func with too many args');55	// @ts-expect-error56	t.deepEqual(bound(1, 2, 3, 4), [hasStrictMode ? 1 : Object(1), 2, 3], 'bound func with too many args');57	// @ts-expect-error58	t.deepEqual(boundR(1, 2, 3), [sentinel, 1, 2], 'bound func with receiver, with too many args');59	// @ts-expect-error60	t.deepEqual(boundArg(2, 3), [sentinel, 1, 2], 'bound func with receiver and arg, with too many args');61 62	t.end();63});64