wip: unit test fixes continued

This commit is contained in:
jdalton
2023-09-21 07:45:49 -07:00
parent bd518dd906
commit a79c5c434c
14 changed files with 66 additions and 77 deletions

View File

@@ -1,35 +1,33 @@
import { _ } from './utils';
import once from '../once';
describe('once', () => {
it('should invoke `func` once', () => {
let count = 0;
const once = _.once(() => ++count);
const resultFunc = once(() => ++count);
once();
expect(once()).toBe(1);
expect(resultFunc()).toBe(1);
expect(count).toBe(1);
});
it('should ignore recursive calls', () => {
let count = 0;
var once = _.once(() => {
once();
var resultFunc = once(() => {
resultFunc();
return ++count;
});
expect(once()).toBe(1);
expect(resultFunc()).toBe(1);
expect(count).toBe(1);
});
it('should not throw more than once', () => {
const once = _.once(() => {
const resultFunc = once(() => {
throw new Error();
});
assert.throws(once);
once();
expect(true);
expect(resultFunc).toThrow();
expect(resultFunc).not.toThrow();
});
});