diff --git a/packages/autocomplete-core/src/__tests__/checkOptions.test.ts b/packages/autocomplete-core/src/__tests__/checkOptions.test.ts new file mode 100644 index 000000000..ebad1a1a1 --- /dev/null +++ b/packages/autocomplete-core/src/__tests__/checkOptions.test.ts @@ -0,0 +1,11 @@ +import { createAutocomplete } from '../createAutocomplete'; + +describe('Validate options', () => { + test('debug option warns about development usage', () => { + expect(() => { + createAutocomplete({ debug: true }); + }).toWarnDev( + '[Autocomplete] The `debug` option is meant for development debugging and should not be used in production.' + ); + }); +}); diff --git a/packages/autocomplete-core/src/checkOptions.ts b/packages/autocomplete-core/src/checkOptions.ts new file mode 100644 index 000000000..a647f93ea --- /dev/null +++ b/packages/autocomplete-core/src/checkOptions.ts @@ -0,0 +1,10 @@ +import { warn } from '@algolia/autocomplete-shared'; + +import { AutocompleteOptions } from './types'; + +export function checkOptions(option: AutocompleteOptions) { + warn( + !option.debug, + 'The `debug` option is meant for development debugging and should not be used in production.' + ); +} diff --git a/packages/autocomplete-core/src/createAutocomplete.ts b/packages/autocomplete-core/src/createAutocomplete.ts index 99a3c1b83..46d61cd32 100644 --- a/packages/autocomplete-core/src/createAutocomplete.ts +++ b/packages/autocomplete-core/src/createAutocomplete.ts @@ -1,3 +1,4 @@ +import { checkOptions } from './checkOptions'; import { createStore } from './createStore'; import { getAutocompleteSetters } from './getAutocompleteSetters'; import { getDefaultProps } from './getDefaultProps'; @@ -14,6 +15,8 @@ export function createAutocomplete< >( options: AutocompleteOptions ): AutocompleteApi { + checkOptions(options); + const props = getDefaultProps(options); const store = createStore(stateReducer, props);