Files
lodash/test/bindAll.js
Benjamin Tan d5ef31929a Add initial test files from lodash v4. (#4172)
* Install test dependencies.

* Add initial test files.

These files were created using a simplistic AST manipulator using `recast` to
preserve formatting. There's bound to be a huge chunk of errors, but this serves
as a good start. QUnit was replaced with Mocha, with ES2015 imports running via
`esm`.

As far as possible, QUnit-specific syntax has been replaced with Mocha's
`describe` and `it`, while the native Node.js `assert` module is used for
assertions. Files in the `test` directory ending in `.test.js` will be treated
as test files.

* Add initial passing files to test run.
2019-02-12 09:11:32 -08:00

75 lines
2.0 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { args, toArgs, arrayProto } from './utils.js';
import bindAll from '../bindAll.js';
describe('bindAll', function() {
var args = toArgs(['a']);
var 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', function() {
var object = lodashStable.cloneDeep(source);
bindAll(object, 'a', 'b');
var actual = lodashStable.map(['a', 'b', 'c'], function(key) {
return object[key].call({});
});
assert.deepStrictEqual(actual, [1, 2, undefined]);
});
it('should accept arrays of method names', function() {
var object = lodashStable.cloneDeep(source);
bindAll(object, ['a', 'b'], ['c']);
var actual = lodashStable.map(['a', 'b', 'c', 'd'], function(key) {
return object[key].call({});
});
assert.deepStrictEqual(actual, [1, 2, 3, undefined]);
});
it('should preserve the sign of `0`', function() {
var props = [-0, Object(-0), 0, Object(0)];
var actual = lodashStable.map(props, function(key) {
var object = lodashStable.cloneDeep(source);
bindAll(object, key);
return object[lodashStable.toString(key)].call({});
});
assert.deepStrictEqual(actual, [-2, -2, -1, -1]);
});
it('should work with an array `object`', function() {
var array = ['push', 'pop'];
bindAll(array);
assert.strictEqual(array.pop, arrayProto.pop);
});
it('should work with `arguments` objects as secondary arguments', function() {
var object = lodashStable.cloneDeep(source);
bindAll(object, args);
var actual = lodashStable.map(args, function(key) {
return object[key].call({});
});
assert.deepStrictEqual(actual, [1]);
});
});