mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
wip: migrate to bun
This commit is contained in:
81
test/isFunction.spec.ts
Normal file
81
test/isFunction.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import assert from 'node:assert';
|
||||
import lodashStable from 'lodash';
|
||||
|
||||
import {
|
||||
slice,
|
||||
asyncFunc,
|
||||
genFunc,
|
||||
arrayViews,
|
||||
objToString,
|
||||
funcTag,
|
||||
falsey,
|
||||
stubFalse,
|
||||
args,
|
||||
symbol,
|
||||
document,
|
||||
realm,
|
||||
} from './utils';
|
||||
|
||||
import isFunction from '../src/isFunction';
|
||||
|
||||
describe('isFunction', () => {
|
||||
it('should return `true` for functions', () => {
|
||||
assert.strictEqual(isFunction(slice), true);
|
||||
});
|
||||
|
||||
it('should return `true` for async functions', () => {
|
||||
assert.strictEqual(isFunction(asyncFunc), typeof asyncFunc === 'function');
|
||||
});
|
||||
|
||||
it('should return `true` for generator functions', () => {
|
||||
assert.strictEqual(isFunction(genFunc), typeof genFunc === 'function');
|
||||
});
|
||||
|
||||
it('should return `true` for the `Proxy` constructor', () => {
|
||||
if (Proxy) {
|
||||
assert.strictEqual(isFunction(Proxy), true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should return `true` for array view constructors', () => {
|
||||
const expected = lodashStable.map(
|
||||
arrayViews,
|
||||
(type) => objToString.call(root[type]) == funcTag,
|
||||
);
|
||||
|
||||
const actual = lodashStable.map(arrayViews, (type) => isFunction(root[type]));
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should return `false` for non-functions', () => {
|
||||
const expected = lodashStable.map(falsey, stubFalse);
|
||||
|
||||
const actual = lodashStable.map(falsey, (value, index) =>
|
||||
index ? isFunction(value) : isFunction(),
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
|
||||
assert.strictEqual(isFunction(args), false);
|
||||
assert.strictEqual(isFunction([1, 2, 3]), false);
|
||||
assert.strictEqual(isFunction(true), false);
|
||||
assert.strictEqual(isFunction(new Date()), false);
|
||||
assert.strictEqual(isFunction(new Error()), false);
|
||||
assert.strictEqual(isFunction({ a: 1 }), false);
|
||||
assert.strictEqual(isFunction(1), false);
|
||||
assert.strictEqual(isFunction(/x/), false);
|
||||
assert.strictEqual(isFunction('a'), false);
|
||||
assert.strictEqual(isFunction(symbol), false);
|
||||
|
||||
if (document) {
|
||||
assert.strictEqual(isFunction(document.getElementsByTagName('body')), false);
|
||||
}
|
||||
});
|
||||
|
||||
it('should work with a function from another realm', () => {
|
||||
if (realm.function) {
|
||||
assert.strictEqual(isFunction(realm.function), true);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user