mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* 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.
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { stubString, symbol } from './utils.js';
|
|
import toString from '../toString.js';
|
|
|
|
describe('toString', function() {
|
|
it('should treat nullish values as empty strings', function() {
|
|
var values = [, null, undefined],
|
|
expected = lodashStable.map(values, stubString);
|
|
|
|
var actual = lodashStable.map(values, function(value, index) {
|
|
return index ? toString(value) : toString();
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should preserve the sign of `0`', function() {
|
|
var values = [-0, Object(-0), 0, Object(0)],
|
|
expected = ['-0', '-0', '0', '0'],
|
|
actual = lodashStable.map(values, toString);
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should preserve the sign of `0` in an array', function() {
|
|
var values = [-0, Object(-0), 0, Object(0)];
|
|
assert.deepStrictEqual(toString(values), '-0,-0,0,0');
|
|
});
|
|
|
|
it('should not error on symbols', function() {
|
|
if (Symbol) {
|
|
try {
|
|
assert.strictEqual(toString(symbol), 'Symbol(a)');
|
|
} catch (e) {
|
|
assert.ok(false, e.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should not error on an array of symbols', function() {
|
|
if (Symbol) {
|
|
try {
|
|
assert.strictEqual(toString([symbol]), 'Symbol(a)');
|
|
} catch (e) {
|
|
assert.ok(false, e.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should return the `toString` result of the wrapped value', function() {
|
|
var wrapped = _([1, 2, 3]);
|
|
assert.strictEqual(wrapped.toString(), '1,2,3');
|
|
});
|
|
});
|