diff --git a/alfa-client/libs/design-system/src/lib/instant-search/instant-search/instant-search.component.spec.ts b/alfa-client/libs/design-system/src/lib/instant-search/instant-search/instant-search.component.spec.ts index 3155008ef5dc91871219e693f62dd499c90d53c2..f6f686486fd74acf8b06bd0a1d3cde94c79831e1 100644 --- a/alfa-client/libs/design-system/src/lib/instant-search/instant-search/instant-search.component.spec.ts +++ b/alfa-client/libs/design-system/src/lib/instant-search/instant-search/instant-search.component.spec.ts @@ -146,11 +146,12 @@ describe('InstantSearchComponent', () => { }); describe('handleArrowNavigation', () => { + const event: KeyboardEvent = new KeyboardEvent('arrow'); + beforeEach(() => { - component.setFocusOnResultItem = jest.fn(); component.getResultIndexForKey = jest.fn(); + component.setFocusOnResultItem = jest.fn(); }); - const event: KeyboardEvent = new KeyboardEvent('arrow'); it('should call prevent default', () => { event.preventDefault = jest.fn(); @@ -160,13 +161,13 @@ describe('InstantSearchComponent', () => { expect(event.preventDefault).toHaveBeenCalled(); }); - it('should call getResultIndexForKey with key of event', () => { + it('should call getResultIndexForKey', () => { component.handleArrowNavigation(event); expect(component.getResultIndexForKey).toHaveBeenCalledWith(event.key); }); - it('should call setFocusOnResultItem new index', () => { + it('should call setFocusOnResultItem', () => { component.getResultIndexForKey = jest.fn().mockReturnValue(0); component.handleArrowNavigation(event); @@ -422,20 +423,12 @@ describe('InstantSearchComponent', () => { }); describe('isArrowNavigationKey', () => { - it('should return true if key is ArrowDown', () => { - const arrowDownEvent = { ...new KeyboardEvent('key'), key: 'ArrowDown' }; + it.each(['ArrowUp', 'ArrowDown'])('should return true for key %s', (key: string) => { + const keyboardEvent: KeyboardEvent = { ...new KeyboardEvent('key'), key }; - const result: boolean = component.isArrowNavigationKey(arrowDownEvent); + const result: boolean = component.isArrowNavigationKey(keyboardEvent); - expect(result).toBe(true); - }); - - it('should return true if key is ArrowUp', () => { - const arrowUpEvent = { ...new KeyboardEvent('navigation'), key: 'ArrowUp' }; - - const result: boolean = component.isArrowNavigationKey(arrowUpEvent); - - expect(result).toBe(true); + expect(result).toBeTruthy(); }); it('should return false', () => {