From dc4ef689f017941f788946142509354d54b9fe67 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 23 Oct 2020 14:55:36 +0200 Subject: [PATCH] change type in test --- .../__tests__/getAutocompleteSetters.test.ts | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/autocomplete-core/src/__tests__/getAutocompleteSetters.test.ts b/packages/autocomplete-core/src/__tests__/getAutocompleteSetters.test.ts index cddec1116..dbc195f8c 100644 --- a/packages/autocomplete-core/src/__tests__/getAutocompleteSetters.test.ts +++ b/packages/autocomplete-core/src/__tests__/getAutocompleteSetters.test.ts @@ -1,4 +1,5 @@ import { createAutocomplete, AutocompleteSuggestion } from '..'; +import { InternalAutocompleteSource } from '../types'; function createSuggestion( items: TItem[] = [] @@ -15,6 +16,26 @@ function createSuggestion( }; } +interface AutocompleteMultiSuggestion { + source: InternalAutocompleteSource; + items: TItem[][]; +} + +function createMultiSuggestion( + items: TItem[][] = [] +): AutocompleteMultiSuggestion { + return { + source: { + getInputValue: ({ suggestion }) => suggestion.label, + getSuggestionUrl: () => undefined, + onHighlight: () => {}, + onSelect: () => {}, + getSuggestions: () => items, + }, + items, + }; +} + describe('createAutocomplete', () => { test('setHighlightedIndex', () => { const onStateChange = jest.fn(); @@ -95,10 +116,9 @@ describe('createAutocomplete', () => { onStateChange, }); - // @ts-expect-error AutocompleteSuggestion has an array of items // while it also accepts a nested array. // There's only one type for both input and output however, - setSuggestions([createSuggestion([[{ label: 'hi' }]])]); + setSuggestions([createMultiSuggestion([[{ label: 'hi' }]])]); expect(onStateChange).toHaveBeenCalledWith({ state: expect.objectContaining({