Skip to content

Commit

Permalink
Better name, better test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Dec 5, 2019
1 parent 8df4f0a commit 6a95be9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,17 @@ describe('hashedItemStore', () => {
});

it('removes and returns an item', () => {
const removedItem = hashedItemStore.removeItem('1');
expect(removedItem).toBe('a');
const removedItem1 = hashedItemStore.removeItem('1');
expect(removedItem1).toBe('a');
expect(hashedItemStore.getItem('1')).toBeNull();
expect(hashedItemStore.getItem('2')).not.toBeNull();
expect((hashedItemStore as any).getIndexedItems()).toHaveLength(1);

const removedItem2 = hashedItemStore.removeItem('2');
expect(removedItem2).toBe('b');
expect(hashedItemStore.getItem('1')).toBeNull();
expect(hashedItemStore.getItem('2')).toBeNull();
expect((hashedItemStore as any).getIndexedItems()).toHaveLength(0);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ export class HashedItemStore implements IStorage<string, boolean> {
removeItem(hash: string): string | null {
const indexedItems = this.getIndexedItems();
const itemToRemove = this.storage.getItem(hash);
const indexToRemove = this.getIndexedItem(hash, indexedItems);
const indexedItemToRemove = this.getIndexedItem(hash, indexedItems);

if (indexToRemove) {
pull(indexedItems, indexToRemove);
if (indexedItemToRemove) {
pull(indexedItems, indexedItemToRemove);
this.setIndexedItems(indexedItems);
}

Expand Down

0 comments on commit 6a95be9

Please sign in to comment.