From 89e70fa6a385d27533e4b883c39f3a5733bd602f Mon Sep 17 00:00:00 2001 From: beefchimi Date: Fri, 22 Dec 2023 11:02:50 -0500 Subject: [PATCH] fix up earwurm test --- src/tests/Earwurm.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests/Earwurm.test.ts b/src/tests/Earwurm.test.ts index 22b80cc..1e7bd5e 100644 --- a/src/tests/Earwurm.test.ts +++ b/src/tests/Earwurm.test.ts @@ -261,6 +261,7 @@ describe('Earwurm component', () => { expect(spyKeysChange).toBeCalledWith(mockInitialKeys, []); expect(spyKeysChange).toBeCalledTimes(1); + // Does not add/remove when both `id + path` are identical. mockManager.add(mockEntries[0]); expect(spyKeysChange).not.toBeCalledTimes(2); @@ -279,6 +280,19 @@ describe('Earwurm component', () => { [...mockInitialKeys, mockUniqueEntry.id], mockInitialKeys, ); + + const keysSnapshot = mockManager.keys; + + // Emits twice as an existing key is removed then re-added + // as a result of the `path` value changing. + mockManager.add({...mockUniqueEntry, path: 'changed'}); + expect(spyKeysChange).toBeCalledTimes(4); + + expect(spyKeysChange).toBeCalledWith(mockInitialKeys, keysSnapshot); + expect(spyKeysChange).toHaveBeenLastCalledWith( + keysSnapshot, + mockInitialKeys, + ); }); // TODO: Figure out how best to read `fadeMs` and `request` from Stack.