mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Ensure _.bind works with ES6 class constructors. [closes #1193]
This commit is contained in:
27
test/test.js
27
test/test.js
@@ -1494,7 +1494,7 @@
|
||||
deepEqual(bound(['b'], 'c'), [object, 'a', ['b'], 'c']);
|
||||
});
|
||||
|
||||
test('should rebind functions', 3, function() {
|
||||
test('should not rebind functions', 3, function() {
|
||||
var object1 = {},
|
||||
object2 = {},
|
||||
object3 = {};
|
||||
@@ -1508,6 +1508,31 @@
|
||||
deepEqual(bound3(), [object1, 'b']);
|
||||
});
|
||||
|
||||
test('should not error when calling bound class constructors', 1, function() {
|
||||
var createCtor = _.attempt(Function, '"use strict";return class A{}');
|
||||
if (typeof createCtor == 'function') {
|
||||
var bound = _.bind(createCtor()),
|
||||
expected = _.times(5, _.constant(true));
|
||||
|
||||
var actual = _.times(5, function(index) {
|
||||
try {
|
||||
switch (index) {
|
||||
case 0: return !!(new bound);
|
||||
case 1: return !!(new bound(1));
|
||||
case 2: return !!(new bound(1, 2));
|
||||
case 3: return !!(new bound(1, 2, 3));
|
||||
case 4: return !!(new bound(1, 2, 3, 4));
|
||||
}
|
||||
} catch(e) {}
|
||||
});
|
||||
|
||||
deepEqual(actual, expected);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when chaining', 2, function() {
|
||||
if (!isNpm) {
|
||||
var object = {},
|
||||
|
||||
Reference in New Issue
Block a user