mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07: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
51
test/pad-methods.js
Normal file
51
test/pad-methods.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { _ } from './utils.js';
|
||||
import pad from '../pad.js';
|
||||
|
||||
describe('pad methods', function() {
|
||||
lodashStable.each(['pad', 'padStart', 'padEnd'], function(methodName) {
|
||||
var func = _[methodName],
|
||||
isPad = methodName == 'pad',
|
||||
isStart = methodName == 'padStart',
|
||||
string = 'abc';
|
||||
|
||||
it('`_.' + methodName + '` should not pad if string is >= `length`', function() {
|
||||
assert.strictEqual(func(string, 2), string);
|
||||
assert.strictEqual(func(string, 3), string);
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should treat negative `length` as `0`', function() {
|
||||
lodashStable.each([0, -2], function(length) {
|
||||
assert.strictEqual(func(string, length), string);
|
||||
});
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should coerce `length` to a number', function() {
|
||||
lodashStable.each(['', '4'], function(length) {
|
||||
var actual = length ? (isStart ? ' abc' : 'abc ') : string;
|
||||
assert.strictEqual(func(string, length), actual);
|
||||
});
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should treat nullish values as empty strings', function() {
|
||||
lodashStable.each([undefined, '_-'], function(chars) {
|
||||
var expected = chars ? (isPad ? '__' : chars) : ' ';
|
||||
assert.strictEqual(func(null, 2, chars), expected);
|
||||
assert.strictEqual(func(undefined, 2, chars), expected);
|
||||
assert.strictEqual(func('', 2, chars), expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('`_.' + methodName + '` should return `string` when `chars` coerces to an empty string', function() {
|
||||
var values = ['', Object('')],
|
||||
expected = lodashStable.map(values, lodashStable.constant(string));
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
return pad(string, 6, value);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user