diff --git a/public/app/features/templating/specs/variable.test.ts b/public/app/features/templating/specs/variable.test.ts index 1590bb939aa..1d78d65719d 100644 --- a/public/app/features/templating/specs/variable.test.ts +++ b/public/app/features/templating/specs/variable.test.ts @@ -85,6 +85,14 @@ describe('containsSearchFilter', () => { }); }); + describe('when called with an object', () => { + it('then it should return false', () => { + const result = containsSearchFilter({}); + + expect(result).toBe(false); + }); + }); + describe(`when called with a query without ${SEARCH_FILTER_VARIABLE}`, () => { it('then it should return false', () => { const result = containsSearchFilter('$app.*'); diff --git a/public/app/features/templating/variable.ts b/public/app/features/templating/variable.ts index 3687ec5742a..09c18b34ddb 100644 --- a/public/app/features/templating/variable.ts +++ b/public/app/features/templating/variable.ts @@ -18,8 +18,8 @@ export const variableRegexExec = (variableString: string) => { export const SEARCH_FILTER_VARIABLE = '__searchFilter'; -export const containsSearchFilter = (query: string): boolean => - query ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false; +export const containsSearchFilter = (query: string | unknown): boolean => + query && typeof query === 'string' ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false; export const getSearchFilterScopedVar = (args: { query: string;