From f6d326cb515c651567f387fc0a21987f2edea785 Mon Sep 17 00:00:00 2001 From: roennibus <90031491+roennibus@users.noreply.github.com> Date: Tue, 7 Jun 2022 17:29:47 +0200 Subject: [PATCH] fix: added unit test --- .../src/lib/tests/hotkeys.service.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/projects/ngneat/hotkeys/src/lib/tests/hotkeys.service.spec.ts b/projects/ngneat/hotkeys/src/lib/tests/hotkeys.service.spec.ts index d372f0c..bf6e803 100644 --- a/projects/ngneat/hotkeys/src/lib/tests/hotkeys.service.spec.ts +++ b/projects/ngneat/hotkeys/src/lib/tests/hotkeys.service.spec.ts @@ -346,6 +346,23 @@ describe('Service: Sequence Hotkeys', () => { return run(); }); + + it('should call callback after clearing and adding sequence shortcut', () => { + const run = async () => { + // * Need to space out time to prevent other test keystrokes from interfering with sequence + await sleep(250); + const spyFcn = createSpy('subscribe', (...args) => {}); + spectator.service.addSequenceShortcut({ keys: 'g>h' }).subscribe(); + spectator.service.removeShortcuts('g>h'); + spectator.service.addSequenceShortcut({ keys: 'g>j' }).subscribe(); + spectator.service.onShortcut(spyFcn); + fakeKeyboardSequencePress(['g', 'j']); + await sleep(250); + expect(spyFcn).toHaveBeenCalled(); + }; + + return run(); +}); it('should add sequence shortcut', () => { spectator.service.addSequenceShortcut({ keys: 'g>i' }).subscribe();