Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: replace findDOMNode() in examples/typescript #9300

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/typescript/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import * as React from 'react';

interface CheckboxWithLabelProps {
labelRef: React.LegacyRef<HTMLLabelElement>;
inputRef: React.LegacyRef<HTMLInputElement>;
labelOff: string;
labelOn: string;
}
Expand All @@ -22,8 +24,9 @@ class CheckboxWithLabel extends React.Component<

render() {
return (
<label>
<label ref={this.props.labelRef}>
<input
ref={this.props.inputRef}
type="checkbox"
checked={this.state.isChecked}
onChange={() =>
Expand Down
24 changes: 15 additions & 9 deletions examples/typescript/__tests__/CheckboxWithLabel-test.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
// import * as ReactDOM from 'react-dom';
import * as TestUtils from 'react-dom/test-utils';

const CheckboxWithLabel = require('../CheckboxWithLabel').default;

it('CheckboxWithLabel changes the text after click', () => {
const checkboxLabelRef: React.RefObject<HTMLLabelElement> = React.createRef();
const checkboxInputRef: React.RefObject<HTMLInputElement> = React.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');
});
4 changes: 1 addition & 3 deletions examples/typescript/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import sum from './sum';

function sub(a: number, b: number): number {
return sum(a, -b);
}
const sub = (a: number, b: number): number => sum(a, -b);

export default sub;
4 changes: 1 addition & 3 deletions examples/typescript/sum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

function sum(a: number, b: number): number {
return a + b;
}
const sum = (a: number, b: number): number => a + b;

export default sum;