Skip to content

Commit

Permalink
Update Memorizer.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Mar 23, 2022
1 parent 0ddc126 commit 7a3c29f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/cspell-lib/src/util/Memorizer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memorizer, memorizeLastCall, callOnce } from './Memorizer';
import { memorizer, memorizeLastCall, callOnce, memorizerAll } from './Memorizer';

describe('Validate Memorizer', () => {
test('the memorizer works', () => {
Expand Down Expand Up @@ -130,3 +130,24 @@ describe('callOnce', () => {
expect(calls).toBe(1);
});
});

describe('memorizerAll', () => {
it('memorizerAll', () => {
function echo(...a: (string | number | undefined)[]): (string | number | undefined)[] {
return a;
}

const mock = jest.fn(echo);
const fn = memorizerAll(mock);
expect(fn('a')).toEqual(['a']);
expect(fn('b')).toEqual(['b']);
expect(fn('a', 'b')).toEqual(['a', 'b']);
expect(fn('a', 'b')).toEqual(['a', 'b']);
expect(fn(undefined)).toEqual([undefined]);
expect(fn('b')).toEqual(['b']);
expect(fn(undefined)).toEqual([undefined]);
expect(fn('a')).toEqual(['a']);
expect(mock).toHaveBeenCalledTimes(4);
expect(mock).toHaveBeenLastCalledWith(undefined);
});
});

0 comments on commit 7a3c29f

Please sign in to comment.