Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Replaces findDomNode() with refs (#9124)
- Loading branch information
Showing
2 changed files
with
18 additions
and
11 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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import React, {createRef} from 'react'; | ||
|
||
import * as TestUtils from 'react-dom/test-utils'; | ||
import CheckboxWithLabel from '../CheckboxWithLabel'; | ||
|
||
it('CheckboxWithLabel changes the text after click', () => { | ||
const checkboxLabelRef = createRef(); | ||
const checkboxInputRef = createRef(); | ||
// Render a checkbox with label in the document | ||
const checkbox = TestUtils.renderIntoDocument( | ||
<CheckboxWithLabel labelOn="On" labelOff="Off" /> | ||
TestUtils.renderIntoDocument( | ||
<CheckboxWithLabel | ||
labelRef={checkboxLabelRef} | ||
inputRef={checkboxInputRef} | ||
labelOn="On" | ||
labelOff="Off" | ||
/> | ||
); | ||
|
||
const checkboxNode = ReactDOM.findDOMNode(checkbox); | ||
const labelNode = checkboxLabelRef.current; | ||
const inputNode = checkboxInputRef.current; | ||
|
||
// Verify that it's Off by default | ||
expect(checkboxNode.textContent).toEqual('Off'); | ||
expect(labelNode.textContent).toEqual('Off'); | ||
|
||
// Simulate a click and verify that it is now On | ||
TestUtils.Simulate.change( | ||
TestUtils.findRenderedDOMComponentWithTag(checkbox, 'input') | ||
); | ||
expect(checkboxNode.textContent).toEqual('On'); | ||
TestUtils.Simulate.change(inputNode); | ||
expect(labelNode.textContent).toEqual('On'); | ||
}); |