Skip to content

Commit

Permalink
Merge f94a970 into 3396e3e
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Apr 25, 2019
2 parents 3396e3e + f94a970 commit 0f92aac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/create-element.js
@@ -1,4 +1,5 @@
import options from './options';
import { assign } from './util';

/**
* Create an virtual node (used for JSX)
Expand All @@ -9,7 +10,8 @@ import options from './options';
* @returns {import('./internal').VNode}
*/
export function createElement(type, props, children) {
if (props==null) props = {};
props = assign({}, props);

if (arguments.length>3) {
children = [children];
for (let i=3; i<arguments.length; i++) {
Expand Down
24 changes: 24 additions & 0 deletions test/browser/render.test.js
Expand Up @@ -4,6 +4,7 @@ import { setupRerender } from 'preact/test-utils';
import { createElement as h, render, Component } from '../../src/index';
import { setupScratch, teardown, getMixedArray, mixedArrayHTML, sortCss, serializeHtml, supportsPassiveEvents, supportsDataList } from '../_util/helpers';
import { clearLog, getLog, logCall } from '../_util/logCall';
import options from '../../src/options';

/** @jsx h */

Expand Down Expand Up @@ -975,6 +976,29 @@ describe('render()', () => {
expect(scratch.textContent).to.equal('01');
});

it('should not cause infinite loop with referentially equal props', () => {
let i = 0;
let prevDiff = options.diff;
options.diff = () => {
if (++i > 10) {
options.diff = prevDiff;
throw new Error('Infinite loop');
}
};

function App({ children, ...rest }) {
return (
<div {...rest}>
<div {...rest}>{children}</div>
</div>
);
}

render(<App>10</App>, scratch);
expect(scratch.textContent).to.equal('10');
options.diff = prevDiff;
});

describe('replaceNode parameter', () => {

function appendChildToScratch(id) {
Expand Down
4 changes: 2 additions & 2 deletions test/shared/createContext.test.js
Expand Up @@ -23,7 +23,7 @@ describe('createContext', () => {

const providerComponent = <Provider {...contextValue}>{children}</Provider>;
//expect(providerComponent).to.have.property('tag', 'Provider');
expect(providerComponent).to.have.property('props', contextValue);
expect(providerComponent).with.nested.deep.property('props.children', children);
expect(providerComponent.props.value).to.equal(contextValue.value);
expect(providerComponent.props.children).to.equal(children);
});
});
2 changes: 1 addition & 1 deletion test/shared/createElement.test.js
Expand Up @@ -39,7 +39,7 @@ describe('createElement(jsx)', () => {

it('should set VNode#props property', () => {
const props = {};
expect(h('div', props)).to.have.property('props', props);
expect(h('div', props).props).to.deep.equal(props);
});

it('should set VNode#text property', () => {
Expand Down

0 comments on commit 0f92aac

Please sign in to comment.