mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
wip: migrate to bun
This commit is contained in:
36
test/once.spec.ts
Normal file
36
test/once.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user