Skip to content

Commit 8fcf649

Browse files
committed
Add attribute->property test
1 parent 37ccabe commit 8fcf649

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

packages/react-dom/src/__tests__/DOMPropertyOperations-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,28 @@ describe('DOMPropertyOperations', () => {
482482
expect(customelement.oncustomevent).toBe(null);
483483
expect(customelement.getAttribute('oncustomevent')).toBe(null);
484484
});
485+
486+
// @gate enableCustomElementPropertySupport
487+
it('assigning to a custom element property should not remove attributes', () => {
488+
const container = document.createElement('div');
489+
document.body.appendChild(container);
490+
ReactDOM.render(<my-custom-element foo="one" />, container);
491+
const customElement = container.querySelector('my-custom-element');
492+
expect(customElement.getAttribute('foo')).toBe('one');
493+
494+
// Install a setter to activate the `in` heuristic
495+
Object.defineProperty(customElement, 'foo', {
496+
set: function(x) {
497+
this._foo = x;
498+
},
499+
get: function() {
500+
return this._foo;
501+
},
502+
});
503+
ReactDOM.render(<my-custom-element foo="two" />, container);
504+
expect(customElement.foo).toBe('two');
505+
expect(customElement.getAttribute('foo')).toBe('one');
506+
});
485507
});
486508

487509
describe('deleteValueForProperty', () => {

0 commit comments

Comments
 (0)