Skip to content

Commit

Permalink
add failing test for #100
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jul 10, 2024
1 parent 2bd551c commit 46426b3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/issue_100.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { memoize } from 'proxy-memoize';

describe('#100', () => {
it('should select correctly', () => {
type State = {
book1: {
staticProp: string;
priceString: string;
};
};

const state1: State = {
book1: {
staticProp: '5',
priceString: '10',
},
};

const state2: State = {
book1: {
staticProp: '5',
priceString: '20',
},
};

const selectAllBooks = memoize((state: State) => Object.values(state));

const selectPriceString = memoize(
(state: State) => state.book1.priceString,
);

const selectAdjustedPriceString = memoize((state: State) => {
const priceString = selectPriceString(state);
state.book1.staticProp; // touch the prop
return priceString;
});

selectAllBooks(state1);

expect(selectAdjustedPriceString(state1)).toBe('10');
expect(selectAdjustedPriceString(state2)).toBe('20');
});
});

0 comments on commit 46426b3

Please sign in to comment.