mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
wip: code formatting nits continued
This commit is contained in:
31
test/sample.spec.js
Normal file
31
test/sample.spec.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import lodashStable from 'lodash';
|
||||
import { empties, noop } from './utils';
|
||||
import sample from '../src/sample';
|
||||
|
||||
describe('sample', () => {
|
||||
const array = [1, 2, 3];
|
||||
|
||||
it('should return a random element', () => {
|
||||
const actual = sample(array);
|
||||
expect(lodashStable.includes(array, actual));
|
||||
});
|
||||
|
||||
it('should return `undefined` when sampling empty collections', () => {
|
||||
const expected = lodashStable.map(empties, noop);
|
||||
|
||||
const actual = lodashStable.transform(empties, (result, value) => {
|
||||
try {
|
||||
result.push(sample(value));
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should sample an object', () => {
|
||||
const object = { a: 1, b: 2, c: 3 };
|
||||
const actual = sample(object);
|
||||
|
||||
expect(lodashStable.includes(array, actual));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user