Skip to content

Commit

Permalink
backport #3968
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 22, 2024
1 parent 4601cf3 commit be85077
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion compat/test/browser/cloneElement.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { createElement as preactH } from 'preact';
import React, { createElement, render, cloneElement } from 'preact/compat';
import React, {
createElement,
render,
cloneElement,
Component
} from 'preact/compat';
import { setupScratch, teardown } from '../../../test/_util/helpers';

describe('compat cloneElement', () => {
Expand Down Expand Up @@ -93,4 +98,17 @@ describe('compat cloneElement', () => {
render(clone, scratch);
expect(scratch.textContent).to.equal('foo');
});

it('should prevent undefined properties from overriding default props', () => {
class Example extends Component {
render(props) {
return <div style={{ color: props.color }}>thing</div>;
}
}
Example.defaultProps = { color: 'blue' };

const element = <Example color="red" />;
const clone = cloneElement(element, { color: undefined });
expect(clone.props.color).to.equal('blue');
});
});

0 comments on commit be85077

Please sign in to comment.