Cleanup error logs on frontend unit test run (#4167)

# What this PR does

Cleanup error logs on frontend unit test run

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall/issues/3428

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
This commit is contained in:
Maxim Mordasov 2024-04-17 12:05:11 +01:00 committed by GitHub
parent e633cf4e82
commit 92600c05a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 31 deletions

View file

@ -45,6 +45,11 @@ Object.defineProperty(window, 'matchMedia', {
})),
});
Object.defineProperty(window, 'location', {
configurable: true,
value: { reload: jest.fn() },
});
Object.defineProperty(window, 'ResizeObserver', {
writable: true,
value: class ResizeObserver {

View file

@ -1,6 +1,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, waitFor } from '@testing-library/react';
import { Provider } from 'mobx-react';
import { UserHelper } from 'models/user/user.helpers';
@ -10,20 +10,20 @@ import { AddRespondersPopup } from './AddRespondersPopup';
describe('AddRespondersPopup', () => {
const teams = [
{
pk: 1,
id: 1,
avatar_url: 'https://example.com',
name: 'my test team',
number_of_users_currently_oncall: 1,
},
{
pk: 2,
id: 2,
avatar_url: 'https://example.com',
name: 'my test team 2',
number_of_users_currently_oncall: 0,
},
];
test('it shows a loading message initially', () => {
test('it shows a loading message initially', async () => {
const mockStoreValue = {
directPagingStore: {
selectedTeamResponder: null,
@ -36,18 +36,20 @@ describe('AddRespondersPopup', () => {
UserHelper.search = jest.fn().mockReturnValue({ results: [] });
const component = render(
<Provider store={mockStoreValue}>
<AddRespondersPopup
mode="create"
visible={true}
setVisible={jest.fn()}
setCurrentlyConsideredUser={jest.fn()}
setShowUserConfirmationModal={jest.fn()}
/>
</Provider>
);
await waitFor(() => {
const component = render(
<Provider store={mockStoreValue}>
<AddRespondersPopup
mode="create"
visible={true}
setVisible={jest.fn()}
setCurrentlyConsideredUser={jest.fn()}
setShowUserConfirmationModal={jest.fn()}
/>
</Provider>
);
expect(component.container).toMatchSnapshot();
expect(component.container).toMatchSnapshot();
});
});
});

View file

@ -40,13 +40,6 @@ const MOCK_HOST = 'localhost:3000';
const MOCK_PATHNAME = '/dkjdfjkfd';
const MOCK_URL = `${MOCK_PROTOCOL}//${MOCK_HOST}${MOCK_PATHNAME}`;
/**
* this is just a little hack to silence a warning that we'll get until we
* upgrade to 16.9. See also: https://github.com/facebook/react/pull/14853
* https://github.com/testing-library/react-testing-library#suppressing-unnecessary-warnings-on-react-dom-168
*/
const originalError = console.error;
beforeEach(() => {
delete global.window.location;
global.window ??= Object.create(window);
@ -57,18 +50,10 @@ beforeEach(() => {
href: MOCK_URL,
} as Location;
global.window.history.pushState = jest.fn();
console.error = (...args) => {
if (/Warning.*not wrapped in act/.test(args[0])) {
return;
}
originalError.call(console, ...args);
};
});
afterEach(() => {
jest.clearAllMocks();
console.error = originalError;
});
const mockCheckTokenAndIfPluginIsConnected = (license: License = License.OSS) => {