mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add initial test files from lodash v4. (#4172)
* 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.
This commit is contained in:
committed by
John-David Dalton
parent
7606ea3e25
commit
d5ef31929a
55
test/toString.test.js
Normal file
55
test/toString.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user