From 7aeecf9a82c4009d82a5b206a6d106ab65382b18 Mon Sep 17 00:00:00 2001 From: Max Nowack Date: Sat, 23 Mar 2024 11:02:45 +0100 Subject: [PATCH] test: add test case for id index removal --- packages/signaldb/__tests__/Collection.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/signaldb/__tests__/Collection.spec.ts b/packages/signaldb/__tests__/Collection.spec.ts index aba38820..2e0af74c 100644 --- a/packages/signaldb/__tests__/Collection.spec.ts +++ b/packages/signaldb/__tests__/Collection.spec.ts @@ -176,6 +176,18 @@ describe('Collection', () => { expect(eventHandler).toHaveBeenCalledTimes(1) expect(eventHandler).toHaveBeenCalledWith({ id: '1', name: 'John' }) }) + + it('should remove the index if the item is removed', () => { + const id = 'test' + collection.insert({ id, name: 'John' }) + expect(collection.findOne({ id })).toEqual({ id, name: 'John' }) + + collection.removeOne({ id }) + expect(collection.findOne({ id })).toBeUndefined() + + collection.insert({ id, name: 'Jane' }) + expect(collection.findOne({ id })).toEqual({ id, name: 'Jane' }) + }) }) describe('removeMany', () => {