mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +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
47
test/startsWith.js
Normal file
47
test/startsWith.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import assert from 'assert';
|
||||
import lodashStable from 'lodash';
|
||||
import { MAX_SAFE_INTEGER, falsey, stubTrue } from './utils.js';
|
||||
import startsWith from '../startsWith.js';
|
||||
|
||||
describe('startsWith', function() {
|
||||
var string = 'abc';
|
||||
|
||||
it('should return `true` if a string starts with `target`', function() {
|
||||
assert.strictEqual(startsWith(string, 'a'), true);
|
||||
});
|
||||
|
||||
it('should return `false` if a string does not start with `target`', function() {
|
||||
assert.strictEqual(startsWith(string, 'b'), false);
|
||||
});
|
||||
|
||||
it('should work with a `position`', function() {
|
||||
assert.strictEqual(startsWith(string, 'b', 1), true);
|
||||
});
|
||||
|
||||
it('should work with `position` >= `length`', function() {
|
||||
lodashStable.each([3, 5, MAX_SAFE_INTEGER, Infinity], function(position) {
|
||||
assert.strictEqual(startsWith(string, 'a', position), false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should treat falsey `position` values as `0`', function() {
|
||||
var expected = lodashStable.map(falsey, stubTrue);
|
||||
|
||||
var actual = lodashStable.map(falsey, function(position) {
|
||||
return startsWith(string, 'a', position);
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should treat a negative `position` as `0`', function() {
|
||||
lodashStable.each([-1, -3, -Infinity], function(position) {
|
||||
assert.strictEqual(startsWith(string, 'a', position), true);
|
||||
assert.strictEqual(startsWith(string, 'b', position), false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should coerce `position` to an integer', function() {
|
||||
assert.strictEqual(startsWith(string, 'bc', 1.2), true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user