Files
lodash/test/startsWith-and-endsWith.js
Benjamin Tan d5ef31929a 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.
2019-02-12 09:11:32 -08:00

39 lines
1.5 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { _, MAX_SAFE_INTEGER } from './utils.js';
describe('startsWith and endsWith', function() {
lodashStable.each(['startsWith', 'endsWith'], function(methodName) {
var func = _[methodName],
isStartsWith = methodName == 'startsWith';
var string = 'abc',
chr = isStartsWith ? 'a' : 'c';
it('`_.' + methodName + '` should coerce `string` to a string', function() {
assert.strictEqual(func(Object(string), chr), true);
assert.strictEqual(func({ 'toString': lodashStable.constant(string) }, chr), true);
});
it('`_.' + methodName + '` should coerce `target` to a string', function() {
assert.strictEqual(func(string, Object(chr)), true);
assert.strictEqual(func(string, { 'toString': lodashStable.constant(chr) }), true);
});
it('`_.' + methodName + '` should coerce `position` to a number', function() {
var position = isStartsWith ? 1 : 2;
assert.strictEqual(func(string, 'b', Object(position)), true);
assert.strictEqual(func(string, 'b', { 'toString': lodashStable.constant(String(position)) }), true);
});
it('should return `true` when `target` is an empty string regardless of `position`', function() {
var positions = [-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity];
assert.ok(lodashStable.every(positions, function(position) {
return func(string, '', position);
}));
});
});
});