-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flare] Adds useListener implementation to ReactDebugHooks (#16205)
- Loading branch information
Showing
2 changed files
with
61 additions
and
3 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
43 changes: 43 additions & 0 deletions
43
packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.internal.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,43 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
* @jest-environment node | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let React; | ||
let ReactDebugTools; | ||
|
||
describe('ReactHooksInspection', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
const ReactFeatureFlags = require('shared/ReactFeatureFlags'); | ||
ReactFeatureFlags.enableFlareAPI = true; | ||
React = require('react'); | ||
ReactDebugTools = require('react-debug-tools'); | ||
}); | ||
|
||
it('should inspect a simple useListener hook', () => { | ||
const TestResponder = React.unstable_createResponder('TestResponder', {}); | ||
|
||
function Foo(props) { | ||
React.unstable_useListener(TestResponder, {preventDefault: false}); | ||
return <div responders={<TestResponder />}>Hello world</div>; | ||
} | ||
let tree = ReactDebugTools.inspectHooks(Foo, {}); | ||
expect(tree).toEqual([ | ||
{ | ||
isStateEditable: false, | ||
id: 0, | ||
name: 'Listener', | ||
value: {props: {preventDefault: false}, responder: 'TestResponder'}, | ||
subHooks: [], | ||
}, | ||
]); | ||
}); | ||
}); |