Skip to content

Commit

Permalink
chore: hide console.error output
Browse files Browse the repository at this point in the history
  • Loading branch information
ymqy committed Feb 10, 2023
1 parent d8d6164 commit dc149df
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
Expand Up @@ -744,7 +744,7 @@ describe('Timeline profiler', () => {
});

it('should mark sync render that throws', async () => {
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down Expand Up @@ -806,7 +806,7 @@ describe('Timeline profiler', () => {
});

it('should mark concurrent render that throws', async () => {
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down Expand Up @@ -1997,7 +1997,7 @@ describe('Timeline profiler', () => {
});

it('should mark sync render that throws', async () => {
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down Expand Up @@ -2092,7 +2092,7 @@ describe('Timeline profiler', () => {
});

it('should mark concurrent render that throws', async () => {
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

class ErrorBoundary extends React.Component {
state = {error: null};
Expand Down
Expand Up @@ -38,7 +38,7 @@ describe('Bridge', () => {
expect(wall.send).toHaveBeenCalledWith('shutdown');

// Verify that the Bridge doesn't send messages after shutdown.
jest.spyOn(console, 'warn');
jest.spyOn(console, 'warn').mockImplementation(() => {});
wall.send.mockClear();
bridge.send('should not send');
jest.runAllTimers();
Expand Down
Expand Up @@ -2121,7 +2121,7 @@ describe('InspectedElement', () => {
});

it('should gracefully surface backend errors on the frontend rather than timing out', async () => {
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});

let shouldThrow = false;

Expand Down Expand Up @@ -2738,7 +2738,7 @@ describe('InspectedElement', () => {

it('inspecting nested renderers should not throw', async () => {
// Ignoring react art warnings
jest.spyOn(console, 'error');
jest.spyOn(console, 'error').mockImplementation(() => {});
const ReactArt = require('react-art');
const ArtSVGMode = require('art/modes/svg');
const ARTCurrentMode = require('art/modes/current');
Expand Down
Expand Up @@ -1135,7 +1135,7 @@ describe('Timeline profiler', () => {
);
const invalidUserTimingData = createUserTimingData(invalidMarks);

const error = jest.spyOn(console, 'error');
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
preprocessData([
...createBoilerplateEntries(),
...invalidUserTimingData,
Expand All @@ -1153,7 +1153,7 @@ describe('Timeline profiler', () => {
);
const invalidUserTimingData = createUserTimingData(invalidMarks);

const error = jest.spyOn(console, 'error');
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
preprocessData([
...createBoilerplateEntries(),
...invalidUserTimingData,
Expand Down
Expand Up @@ -73,7 +73,7 @@ describe('ProfilerStore', () => {
const fauxProfilingData = {
dataForRoots: new Map(),
};
jest.spyOn(console, 'warn');
jest.spyOn(console, 'warn').mockImplementation(() => {});
store.profilerStore.profilingData = fauxProfilingData;
expect(store.profilerStore.profilingData).not.toBe(fauxProfilingData);
expect(console.warn).toHaveBeenCalledTimes(1);
Expand Down
Expand Up @@ -67,16 +67,20 @@ module.exports = function (initModules) {
// performs fn asynchronously and expects count errors logged to console.error.
// will fail the test if the count of errors logged is not equal to count.
async function expectErrors(fn, count) {
if (console.error.mockReset) {
console.error.mockReset();
if (console.error.mockClear) {
console.error.mockClear();
} else {
// TODO: Rewrite tests that use this helper to enumerate expected errors.
// This will enable the helper to use the .toErrorDev() matcher instead of spying.
spyOnDev(console, 'error').mockImplementation(() => {});
}

const result = await fn();
if (console.error.mock.calls && console.error.mock.calls.length !== 0) {
if (
console.error.mock &&
console.error.mock.calls &&
console.error.mock.calls.length !== 0
) {
const filteredWarnings = [];
for (let i = 0; i < console.error.mock.calls.length; i++) {
const args = console.error.mock.calls[i];
Expand Down

0 comments on commit dc149df

Please sign in to comment.