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.
35 lines
806 B
35 lines
806 B
import moize from '../src'; |
|
|
|
type Arg = { |
|
one: number; |
|
two: { |
|
deep: number; |
|
}; |
|
}; |
|
|
|
const method = jest.fn(function ({ one, two }: Arg) { |
|
return [one, two.deep]; |
|
}); |
|
|
|
const memoized = moize.shallow(method); |
|
|
|
describe('moize.shallow', () => { |
|
it('should memoized based on the shallow values', () => { |
|
const two = { deep: 2 }; |
|
|
|
const resultA = memoized({ one: 1, two }); |
|
const resultB = memoized({ one: 1, two }); |
|
|
|
expect(resultA).toEqual([1, 2]); |
|
expect(resultA).toBe(resultB); |
|
|
|
expect(method).toHaveBeenCalledTimes(1); |
|
|
|
const resultC = memoized({ one: 1, two: { ...two } }); |
|
|
|
expect(resultC).toEqual(resultA); |
|
expect(resultC).not.toBe(resultA); |
|
|
|
expect(method).toHaveBeenCalledTimes(2); |
|
}); |
|
});
|
|
|