Stub console.warn (#45311)

This commit is contained in:
Ashley Harrison 2022-02-11 14:56:25 +00:00 committed by GitHub
parent 6a776c78d4
commit 378ce15418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,18 @@ import { CustomEndpointTransport } from './CustomEndpointTransport';
describe('CustomEndpointTransport', () => {
const fetchSpy = (window.fetch = jest.fn());
beforeEach(() => jest.resetAllMocks());
let consoleSpy: jest.SpyInstance;
beforeEach(() => {
jest.resetAllMocks();
// The code logs a warning to console
// Let's stub this out so we don't pollute the test output
consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
});
afterEach(() => {
consoleSpy.mockRestore();
});
const now = new Date();
const event: Event = {
@ -87,7 +98,7 @@ describe('CustomEndpointTransport', () => {
expect(fetchSpy).toHaveBeenCalledTimes(2);
});
it('will drop events if max concurrency is reached', async () => {
it('will drop events and log a warning to console if max concurrency is reached', async () => {
const calls: Array<(value: unknown) => void> = [];
fetchSpy.mockImplementation(
() =>