Ensure _.toString works on an array of symbols.

This commit is contained in:
John-David Dalton
2016-10-05 09:05:51 -07:00
parent d2f74ee245
commit 836bd258a0
2 changed files with 26 additions and 0 deletions

View File

@@ -4230,6 +4230,10 @@
if (typeof value == 'string') {
return value;
}
if (isArray(value)) {
// Recursively convert values (susceptible to call stack limits).
return arrayMap(value, baseToString) + '';
}
if (isSymbol(value)) {
return symbolToString ? symbolToString.call(value) : '';
}

View File

@@ -23714,6 +23714,13 @@
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) {
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) {
assert.expect(1);