Files
lodash/test/once.spec.ts
2023-09-16 14:47:50 -07:00

37 lines
767 B
TypeScript

import assert from 'node:assert';
import { _ } from './utils';
describe('once', () => {
it('should invoke `func` once', () => {
let count = 0,
once = _.once(() => ++count);
once();
assert.strictEqual(once(), 1);
assert.strictEqual(count, 1);
});
it('should ignore recursive calls', () => {
let count = 0;
var once = _.once(() => {
once();
return ++count;
});
assert.strictEqual(once(), 1);
assert.strictEqual(count, 1);
});
it('should not throw more than once', () => {
const once = _.once(() => {
throw new Error();
});
assert.throws(once);
once();
assert.ok(true);
});
});