Skip to content

Commit

Permalink
Fix tests to check we throw after all
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 2, 2018
1 parent 6fc3e18 commit 0c1ded6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ class Bad extends React.Component {
}
}

describe('ReactNestedUpdateBug', () => {
describe('ReactErrorLoggingRecovery', () => {
let originalConsoleError = console.error;

beforeEach(() => {
console.error = error => {
throw new Error(error);
throw new Error('Buggy console.error');
};
});

afterEach(() => {
console.error = originalConsoleError;
});

it('should mount', function() {
it('should recover from errors in console.error', function() {
const div = document.createElement('div');
let didCatch = false;
try {
Expand All @@ -70,5 +70,10 @@ describe('ReactNestedUpdateBug', () => {
expect(didCatch).toBe(true);
ReactDOM.render(<span>Hello</span>, div);
expect(div.firstChild.textContent).toBe('Hello');

// Verify
expect(() => {
jest.runAllTimers();
}).toThrow('Buggy console.error');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ describe('ReactIncrementalErrorLogging', () => {

expect(logCapturedErrorCalls.length).toBe(1);

// The error thrown in logCapturedError should also be logged
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error.calls.argsFor(0)[0].message).toContain(
'logCapturedError error',
);
// The error thrown in logCapturedError should be rethrown with a clean stack
expect(() => {
jest.runAllTimers();
}).toThrow('logCapturedError error');
} finally {
jest.unmock('../ReactFiberErrorLogger');
}
Expand Down

0 comments on commit 0c1ded6

Please sign in to comment.