Skip to content

Commit

Permalink
Merge branch 'master' into feat/putt-putt-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianbote committed May 7, 2019
2 parents 5056ac8 + 719a2e8 commit 5fb41c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export function createElement(type, props, children) {
}
}
let ref = props.ref;
if (ref) delete props.ref;
let key = props.key;
if (key) delete props.key;
if (ref!=null) delete props.ref;
if (key!=null) delete props.key;

return createVNode(type, props, key, ref);
}
Expand Down
12 changes: 12 additions & 0 deletions test/shared/createElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,25 @@ describe('createElement(jsx)', () => {
expect(<div key="1" />).to.have.property('key', '1');
});

it('should not set VNode#props.key property', () => {
expect(<div />).to.not.have.nested.property('props.key');
expect(<div key="1" />).to.not.have.nested.property('props.key');
expect(<div key={0} />).to.not.have.nested.property('props.key');
expect(<div key={''} />).to.not.have.nested.property('props.key');
});

it('should set VNode#ref property', () => {
expect(<div />).to.have.property('ref').that.is.undefined;
expect(<div a="a" />).to.have.property('ref').that.is.undefined;
const emptyFunction = () => {};
expect(<div ref={emptyFunction} />).to.have.property('ref', emptyFunction);
});

it('should not set VNode#props.ref property', () => {
expect(<div />).to.not.have.nested.property('props.ref');
expect(<div ref={() => {}} />).to.not.have.nested.property('props.ref');
});

it('should have ordered VNode properties', () => {
expect(Object.keys(<div />).filter(key => !/^_/.test(key))).to.deep.equal(['type', 'props', 'key', 'ref']);
});
Expand Down

0 comments on commit 5fb41c5

Please sign in to comment.