wip: code formatting nits continued

This commit is contained in:
jdalton
2023-09-16 22:59:56 -07:00
parent 0b28b7f7b6
commit b5c59317ea
421 changed files with 7354 additions and 9005 deletions

79
test/bindAll.spec.js Normal file
View File

@@ -0,0 +1,79 @@
import lodashStable from 'lodash';
import { args, toArgs, arrayProto } from './utils';
import bindAll from '../src/bindAll';
describe('bindAll', () => {
const args = toArgs(['a']);
const source = {
_n0: -2,
_p0: -1,
_a: 1,
_b: 2,
_c: 3,
_d: 4,
'-0': function () {
return this._n0;
},
0: function () {
return this._p0;
},
a: function () {
return this._a;
},
b: function () {
return this._b;
},
c: function () {
return this._c;
},
d: function () {
return this._d;
},
};
it('should accept individual method names', () => {
const object = lodashStable.cloneDeep(source);
bindAll(object, 'a', 'b');
const actual = lodashStable.map(['a', 'b', 'c'], (key) => object[key].call({}));
expect(actual, [1, 2).toEqual(undefined]);
});
it('should accept arrays of method names', () => {
const object = lodashStable.cloneDeep(source);
bindAll(object, ['a', 'b'], ['c']);
const actual = lodashStable.map(['a', 'b', 'c', 'd'], (key) => object[key].call({}));
expect(actual, [1, 2, 3).toEqual(undefined]);
});
it('should preserve the sign of `0`', () => {
const props = [-0, Object(-0), 0, Object(0)];
const actual = lodashStable.map(props, (key) => {
const object = lodashStable.cloneDeep(source);
bindAll(object, key);
return object[lodashStable.toString(key)].call({});
});
expect(actual, [-2, -2, -1).toEqual(-1]);
});
it('should work with an array `object`', () => {
const array = ['push', 'pop'];
bindAll(array);
expect(array.pop).toBe(arrayProto.pop);
});
it('should work with `arguments` objects as secondary arguments', () => {
const object = lodashStable.cloneDeep(source);
bindAll(object, args);
const actual = lodashStable.map(args, (key) => object[key].call({}));
expect(actual).toEqual([1]);
});
});