Chore: Fix a couple more console errors in jest tests (#46732)

* Chore: Fix a couple more console errors in jest tests

* remove console.errors

* better spy

* Fix linting
This commit is contained in:
Ashley Harrison
2022-03-18 16:25:59 +00:00
committed by GitHub
parent c592e6606c
commit 6eecd021a4
3 changed files with 10 additions and 5 deletions

View File

@@ -183,6 +183,15 @@ describe('graphiteDatasource', () => {
describe('when fetching Graphite Events as annotations', () => {
let results: any;
let errorSpy: jest.SpyInstance;
beforeEach(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation();
});
afterEach(() => {
errorSpy.mockRestore();
});
const options = {
annotation: {
@@ -260,6 +269,7 @@ describe('graphiteDatasource', () => {
results = data;
});
expect(results).toEqual([]);
expect(console.error).toHaveBeenCalledWith(expect.stringMatching(/Unable to get annotations/));
});
});

View File

@@ -1,7 +1,6 @@
import { dispatch } from 'app/store/store';
import gfunc from '../gfunc';
import { TemplateSrvStub } from 'test/specs/helpers';
import { silenceConsoleOutput } from 'test/core/utils/silenceConsoleOutput';
import { actions } from '../state/actions';
import {
getAltSegmentsSelectables,
@@ -236,7 +235,6 @@ describe('Graphite actions', () => {
});
describe('when autocomplete for metric names is not available', () => {
silenceConsoleOutput();
beforeEach(() => {
ctx.state.datasource.getTagsAutoComplete = jest.fn().mockReturnValue(Promise.resolve([]));
ctx.state.datasource.metricFindQuery = jest.fn().mockReturnValue(
@@ -267,7 +265,6 @@ describe('Graphite actions', () => {
});
describe('when autocomplete for tags is not available', () => {
silenceConsoleOutput();
beforeEach(() => {
ctx.datasource.metricFindQuery = jest.fn().mockReturnValue(Promise.resolve([]));
ctx.datasource.getTagsAutoComplete = jest.fn().mockReturnValue(

View File

@@ -172,7 +172,6 @@ export function handleMetricsAutoCompleteError(
state: GraphiteQueryEditorState,
error: Error
): GraphiteQueryEditorState {
console.error(error);
if (!state.metricAutoCompleteErrorShown) {
state.metricAutoCompleteErrorShown = true;
dispatch(notifyApp(createErrorNotification(`Fetching metrics failed: ${error.message}.`)));
@@ -184,7 +183,6 @@ export function handleMetricsAutoCompleteError(
* When tags autocomplete fails - the error is shown, but only once per page view
*/
export function handleTagsAutoCompleteError(state: GraphiteQueryEditorState, error: Error): GraphiteQueryEditorState {
console.error(error);
if (!state.tagsAutoCompleteErrorShown) {
state.tagsAutoCompleteErrorShown = true;
dispatch(notifyApp(createErrorNotification(`Fetching tags failed: ${error.message}.`)));