You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
695 B

2 years ago
import moize from '../src';
const method = jest.fn(function (one: string, two?: string) {
return { one, two };
});
function argMatcher(cacheKeyArg: string, keyArg: string) {
return cacheKeyArg === 'foo' || keyArg === 'foo';
}
const memoized = moize.matchesArg(argMatcher)(method);
const foo = 'foo';
const bar = 'bar';
describe('moize.matchesArg', () => {
it('performs a custom equality check of specific args in the key', () => {
const resultA = memoized(foo, bar);
const resultB = memoized(bar, foo);
expect(resultA).toEqual({ one: foo, two: bar });
expect(resultB).toBe(resultA);
expect(method).toHaveBeenCalledTimes(1);
});
});