Skip to content

Commit

Permalink
Fix a broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 3, 2020
1 parent 414f3ab commit 9402084
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,15 +1625,39 @@ describe('ReactDOMInput', () => {
const originalCreateElement = document.createElement;
spyOnDevAndProd(document, 'createElement').and.callFake(function(type) {
const el = originalCreateElement.apply(this, arguments);
let value = '';
const getDefaultValue = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
'defaultValue',
).get;
const setDefaultValue = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
'defaultValue',
).set;
const getValue = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
'value',
).get;
const setValue = Object.getOwnPropertyDescriptor(
HTMLInputElement.prototype,
'value',
).set;
if (type === 'input') {
Object.defineProperty(el, 'defaultValue', {
get: function() {
return getDefaultValue.call(this);
},
set: function(val) {
log.push(`node.defaultValue = ${strify(val)}`);
setDefaultValue.call(this, val);
},
});
Object.defineProperty(el, 'value', {
get: function() {
return value;
return getValue.call(this);
},
set: function(val) {
value = '' + val;
log.push(`node.value = ${strify(val)}`);
setValue.call(this, val);
},
});
spyOnDevAndProd(el, 'setAttribute').and.callFake(function(name, val) {
Expand All @@ -1648,12 +1672,18 @@ describe('ReactDOMInput', () => {
if (disableInputAttributeSyncing) {
expect(log).toEqual([
'node.setAttribute("type", "date")',
'node.setAttribute("value", "1980-01-01")',
'node.defaultValue = "1980-01-01"',
// TODO: it's possible this reintroduces the bug because we don't assign `value` at all.
// Need to check this on mobile Safari and Chrome.
]);
} else {
expect(log).toEqual([
'node.setAttribute("type", "date")',
// value must be assigned before defaultValue. This fixes an issue where the
// visually displayed value of date inputs disappears on mobile Safari and Chrome:
// https://github.com/facebook/react/issues/7233
'node.value = "1980-01-01"',
'node.defaultValue = "1980-01-01"',
]);
}
});
Expand Down

0 comments on commit 9402084

Please sign in to comment.