Make _.uniqueId consistently return a string value.

Former-commit-id: 5a5c626df83b0fc78e9bae37510680383f112c0b
This commit is contained in:
John-David Dalton
2012-11-29 22:17:00 -08:00
parent 529c5b8abf
commit 619ba13265
7 changed files with 165 additions and 134 deletions

View File

@@ -698,6 +698,10 @@
equal(lodash.some([false, true, false]), true, '_.some: ' + basename);
equal(lodash.template('${a}', object), '${a}', '_.template should ignore ES6 delimiters: ' + basename);
actual = [lodash.uniqueId(3), lodash.uniqueId(2), lodash.uniqueId(1)];
equal(actual.join(','), '3,3,3', '_.uniqueId should not coerce the prefix argument to a string: ' + basename);
equal(typeof lodash.uniqueId(), 'number', '_.uniqueId should return a number value when not passing a prefix argument: ' + basename);
var wrapped = lodash(1);
equal(wrapped.clone() instanceof lodash, false, '_(...) wrapped values are not chainable by default: ' + basename);
equal(String(wrapped) === '1', false, '_#toString should not be implemented: ' + basename);

View File

@@ -1878,6 +1878,21 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.uniqueId');
(function() {
test('should return a string value when not passing a prefix argument', function() {
equal(typeof _.uniqueId(), 'string');
});
test('should coerce the prefix argument to a string', function() {
var actual = [_.uniqueId(3), _.uniqueId(2), _.uniqueId(1)];
equal(/3\d+,2\d+,1\d+/.test(actual), true);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.where');
(function() {