Skip to content
Merged
Changes from 5 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
39 changes: 32 additions & 7 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('ReactDOMComponent', () => {
var ReactTestUtils;
var ReactDOM;
var ReactDOMServer;
var inputValueTracking;

function normalizeCodeLocInfo(str) {
return str && str.replace(/\(at .+?:\d+\)/g, '(at **)');
Expand All @@ -26,8 +25,6 @@ describe('ReactDOMComponent', () => {
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
inputValueTracking = require('../client/inputValueTracking');
});

describe('updateDOM', () => {
Expand Down Expand Up @@ -1152,18 +1149,46 @@ describe('ReactDOMComponent', () => {
container,
);

var tracker = inputValueTracking._getTrackerFromNode(inst);
var getValueTracker = Object.getOwnPropertyDescriptor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ideally be done before React is imported.

HTMLInputElement.prototype,
'value',
).get;

expect(tracker.getValue()).toEqual('foo');
expect(getValueTracker.call(inst)).toEqual('foo');

inst.defaultValue = 'new foo';
expect(getValueTracker.call(inst)).not.toEqual('new foo');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant. You already check for the other value later.

expect(getValueTracker.call(inst)).toEqual('foo');

inst.value = 'bar';
expect(getValueTracker.call(inst)).toEqual('bar');

// even if the value changes to empty string, should not return to defaultValue
inst.value = '';
expect(getValueTracker.call(inst)).toEqual('');
});

it('should track textarea values', () => {
var container = document.createElement('div');
var inst = ReactDOM.render(<textarea defaultValue="foo" />, container);

var tracker = inputValueTracking._getTrackerFromNode(inst);
var getValueTracker = Object.getOwnPropertyDescriptor(
HTMLTextAreaElement.prototype,
'value',
).get;

expect(getValueTracker.call(inst)).toEqual('foo');

inst.defaultValue = 'new foo';
expect(getValueTracker.call(inst)).not.toEqual('new foo');
expect(getValueTracker.call(inst)).toEqual('foo');

inst.value = 'bar';
expect(getValueTracker.call(inst)).toEqual('bar');

expect(tracker.getValue()).toEqual('foo');
// even if the value changes to empty string, should not return to defaultValue
inst.value = '';
expect(getValueTracker.call(inst)).toEqual('');
});

it('should throw for children on void elements', () => {
Expand Down