mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
31 lines
770 B
TypeScript
31 lines
770 B
TypeScript
import assert from 'node:assert';
|
|
|
|
describe('tap', () => {
|
|
it('should intercept and return the given value', () => {
|
|
let intercepted,
|
|
array = [1, 2, 3];
|
|
|
|
const actual = _.tap(array, (value) => {
|
|
intercepted = value;
|
|
});
|
|
|
|
assert.strictEqual(actual, array);
|
|
assert.strictEqual(intercepted, array);
|
|
});
|
|
|
|
it('should intercept unwrapped values and return wrapped values when chaining', () => {
|
|
let intercepted,
|
|
array = [1, 2, 3];
|
|
|
|
const wrapped = _(array).tap((value) => {
|
|
intercepted = value;
|
|
value.pop();
|
|
});
|
|
|
|
assert.ok(wrapped instanceof _);
|
|
|
|
wrapped.value();
|
|
assert.strictEqual(intercepted, array);
|
|
});
|
|
});
|