Skip to content

Commit 2a2e3dd

Browse files
feat(core): warn when using debug option (#364)
1 parent eed934f commit 2a2e3dd

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createAutocomplete } from '../createAutocomplete';
2+
3+
describe('Validate options', () => {
4+
test('debug option warns about development usage', () => {
5+
expect(() => {
6+
createAutocomplete({ debug: true });
7+
}).toWarnDev(
8+
'[Autocomplete] The `debug` option is meant for development debugging and should not be used in production.'
9+
);
10+
});
11+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { warn } from '@algolia/autocomplete-shared';
2+
3+
import { AutocompleteOptions } from './types';
4+
5+
export function checkOptions<TItem>(option: AutocompleteOptions<TItem>) {
6+
warn(
7+
!option.debug,
8+
'The `debug` option is meant for development debugging and should not be used in production.'
9+
);
10+
}

packages/autocomplete-core/src/createAutocomplete.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { checkOptions } from './checkOptions';
12
import { createStore } from './createStore';
23
import { getAutocompleteSetters } from './getAutocompleteSetters';
34
import { getDefaultProps } from './getDefaultProps';
@@ -14,6 +15,8 @@ export function createAutocomplete<
1415
>(
1516
options: AutocompleteOptions<TItem>
1617
): AutocompleteApi<TItem, TEvent, TMouseEvent, TKeyboardEvent> {
18+
checkOptions(options);
19+
1720
const props = getDefaultProps(options);
1821
const store = createStore(stateReducer, props);
1922

0 commit comments

Comments
 (0)