-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6605 from gaearon/fix-warning-condition
Fix the warning condition in ReactDebugTool and ReactDOMDebugTool (cherry picked from commit 7dbc95f)
- Loading branch information
Showing
4 changed files
with
158 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('ReactDebugTool', function() { | ||
var ReactDebugTool; | ||
|
||
beforeEach(function() { | ||
jest.resetModuleRegistry(); | ||
ReactDebugTool = require('ReactDebugTool'); | ||
}); | ||
|
||
it('should add and remove devtools', () => { | ||
var handler1 = jasmine.createSpy('spy'); | ||
var handler2 = jasmine.createSpy('spy'); | ||
var devtool1 = {onTestEvent: handler1}; | ||
var devtool2 = {onTestEvent: handler2}; | ||
|
||
ReactDebugTool.addDevtool(devtool1); | ||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(1); | ||
expect(handler2.calls.length).toBe(0); | ||
|
||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(2); | ||
expect(handler2.calls.length).toBe(0); | ||
|
||
ReactDebugTool.addDevtool(devtool2); | ||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(3); | ||
expect(handler2.calls.length).toBe(1); | ||
|
||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(2); | ||
|
||
ReactDebugTool.removeDevtool(devtool1); | ||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(3); | ||
|
||
ReactDebugTool.removeDevtool(devtool2); | ||
ReactDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(3); | ||
}); | ||
|
||
it('warns once when an error is thrown in devtool', () => { | ||
spyOn(console, 'error'); | ||
ReactDebugTool.addDevtool({ | ||
onTestEvent() { | ||
throw new Error('Hi.'); | ||
}, | ||
}); | ||
|
||
ReactDebugTool.onTestEvent(); | ||
expect(console.error.calls.length).toBe(1); | ||
expect(console.error.argsForCall[0][0]).toContain( | ||
'exception thrown by devtool while handling ' + | ||
'onTestEvent: Hi.' | ||
); | ||
|
||
ReactDebugTool.onTestEvent(); | ||
expect(console.error.calls.length).toBe(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
75 changes: 75 additions & 0 deletions
75
src/renderers/dom/shared/__tests__/ReactDOMDebugTool-test.js
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,75 @@ | ||
/** | ||
* Copyright 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('ReactDOMDebugTool', function() { | ||
var ReactDOMDebugTool; | ||
|
||
beforeEach(function() { | ||
jest.resetModuleRegistry(); | ||
ReactDOMDebugTool = require('ReactDOMDebugTool'); | ||
}); | ||
|
||
it('should add and remove devtools', () => { | ||
var handler1 = jasmine.createSpy('spy'); | ||
var handler2 = jasmine.createSpy('spy'); | ||
var devtool1 = {onTestEvent: handler1}; | ||
var devtool2 = {onTestEvent: handler2}; | ||
|
||
ReactDOMDebugTool.addDevtool(devtool1); | ||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(1); | ||
expect(handler2.calls.length).toBe(0); | ||
|
||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(2); | ||
expect(handler2.calls.length).toBe(0); | ||
|
||
ReactDOMDebugTool.addDevtool(devtool2); | ||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(3); | ||
expect(handler2.calls.length).toBe(1); | ||
|
||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(2); | ||
|
||
ReactDOMDebugTool.removeDevtool(devtool1); | ||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(3); | ||
|
||
ReactDOMDebugTool.removeDevtool(devtool2); | ||
ReactDOMDebugTool.onTestEvent(); | ||
expect(handler1.calls.length).toBe(4); | ||
expect(handler2.calls.length).toBe(3); | ||
}); | ||
|
||
it('warns once when an error is thrown in devtool', () => { | ||
spyOn(console, 'error'); | ||
ReactDOMDebugTool.addDevtool({ | ||
onTestEvent() { | ||
throw new Error('Hi.'); | ||
}, | ||
}); | ||
|
||
ReactDOMDebugTool.onTestEvent(); | ||
expect(console.error.calls.length).toBe(1); | ||
expect(console.error.argsForCall[0][0]).toContain( | ||
'exception thrown by devtool while handling ' + | ||
'onTestEvent: Hi.' | ||
); | ||
|
||
ReactDOMDebugTool.onTestEvent(); | ||
expect(console.error.calls.length).toBe(1); | ||
}); | ||
}); |