Skip to content

Commit

Permalink
add failing test for #96
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jan 28, 2024
1 parent c9c89c0 commit 321ef6f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions __tests__/issue_96_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { memoize } from '../src/index';

describe('unused selectors (#96)', () => {
it('nested memoized selectors with primitive value access', () => {
type State = {
ids: string[];
entities: {
[id: string]: { name: string, array: string[] };
};
};
const state1: State = {
ids: ['1'],
entities: {
1: { name: 'first', array: [] },
},
};
const state2: State = {
ids: ['1'],
entities: {
1: { name: 'first', array: ['changed'] },
},
};
const selectAll = memoize((state: State) => state.ids.map((id) => state.entities[id]));
const selectAllNames = memoize((state: State) => (
state.ids.map((id) => state.entities[id]?.name)
));
const intermediateSelector = memoize((state: State) => {
selectAllNames(state);
return selectAll(state);
});
const finalSelector = memoize((state: State) => {
const combinedResult = intermediateSelector(state);
return combinedResult;
});
const result1 = finalSelector(state1);
const result2 = finalSelector(state2);
expect(result1).not.toEqual(result2);
});
});

0 comments on commit 321ef6f

Please sign in to comment.