mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Ensure _.toString works on an array of symbols.
This commit is contained in:
@@ -4230,6 +4230,10 @@
|
|||||||
if (typeof value == 'string') {
|
if (typeof value == 'string') {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
if (isArray(value)) {
|
||||||
|
// Recursively convert values (susceptible to call stack limits).
|
||||||
|
return arrayMap(value, baseToString) + '';
|
||||||
|
}
|
||||||
if (isSymbol(value)) {
|
if (isSymbol(value)) {
|
||||||
return symbolToString ? symbolToString.call(value) : '';
|
return symbolToString ? symbolToString.call(value) : '';
|
||||||
}
|
}
|
||||||
|
|||||||
22
test/test.js
22
test/test.js
@@ -23714,6 +23714,13 @@
|
|||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should preserve the sign of `0` in an array', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var values = [-0, Object(-0), 0, Object(0)];
|
||||||
|
assert.deepEqual(_.toString(values), '-0,-0,0,0');
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should not error on symbols', function(assert) {
|
QUnit.test('should not error on symbols', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
@@ -23729,6 +23736,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('should not error on an array of symbols', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
if (Symbol) {
|
||||||
|
try {
|
||||||
|
assert.strictEqual(_.toString([symbol]), 'Symbol(a)');
|
||||||
|
} catch (e) {
|
||||||
|
assert.ok(false, e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipAssert(assert);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
|
QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user