-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pass testConsole to TestEnvironment (#5227)
- Loading branch information
Showing
8 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
/* eslint-env browser */ | ||
'use strict'; | ||
|
||
beforeEach(() => { | ||
jest.spyOn(console, 'error'); | ||
console.error.mockImplementation(() => {}); | ||
}); | ||
|
||
afterEach(() => { | ||
console.error.mockRestore(); | ||
}); | ||
|
||
test('can mock console.error calls from jsdom', () => { | ||
// copied and modified for tests from: | ||
// https://github.com/facebook/react/blob/46b3c3e4ae0d52565f7ed2344036a22016781ca0/packages/shared/invokeGuardedCallback.js#L62-L147 | ||
const fakeNode = document.createElement('react'); | ||
|
||
const evt = document.createEvent('Event'); | ||
const evtType = 'react-invokeguardedcallback'; | ||
function callCallback() { | ||
fakeNode.removeEventListener(evtType, callCallback, false); | ||
throw new Error('this is an error in an event callback'); | ||
} | ||
|
||
function onError(event) {} | ||
|
||
window.addEventListener('error', onError); | ||
fakeNode.addEventListener(evtType, callCallback, false); | ||
evt.initEvent(evtType, false, false); | ||
fakeNode.dispatchEvent(evt); | ||
window.removeEventListener('error', onError); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "jsdom" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters