Skip to content

Commit

Permalink
feat(core): warn when using debug option (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored Nov 10, 2020
1 parent eed934f commit 2a2e3dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/autocomplete-core/src/__tests__/checkOptions.test.ts
Original file line number Diff line number Diff line change
@@ -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.'
);
});
});
10 changes: 10 additions & 0 deletions packages/autocomplete-core/src/checkOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { warn } from '@algolia/autocomplete-shared';

import { AutocompleteOptions } from './types';

export function checkOptions<TItem>(option: AutocompleteOptions<TItem>) {
warn(
!option.debug,
'The `debug` option is meant for development debugging and should not be used in production.'
);
}
3 changes: 3 additions & 0 deletions packages/autocomplete-core/src/createAutocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { checkOptions } from './checkOptions';
import { createStore } from './createStore';
import { getAutocompleteSetters } from './getAutocompleteSetters';
import { getDefaultProps } from './getDefaultProps';
Expand All @@ -14,6 +15,8 @@ export function createAutocomplete<
>(
options: AutocompleteOptions<TItem>
): AutocompleteApi<TItem, TEvent, TMouseEvent, TKeyboardEvent> {
checkOptions(options);

const props = getDefaultProps(options);
const store = createStore(stateReducer, props);

Expand Down

0 comments on commit 2a2e3dd

Please sign in to comment.