Skip to content

Commit

Permalink
Fix props and debug methods for SFCs
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandrichardson committed Mar 15, 2016
1 parent c711f13 commit 363c393
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function debugInst(inst, indentLength = 2) {
const publicInst = inst.getPublicInstance();

if (typeof publicInst === 'string' || typeof publicInst === 'number') return escape(publicInst);
if (!publicInst) return '';
if (!publicInst && !inst._renderedComponent) return '';

// do stuff with publicInst
const currentElement = inst._currentElement;
Expand Down
3 changes: 3 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export function propsOfNode(node) {
if (node && node._reactInternalComponent && node._reactInternalComponent._currentElement) {
return (node._reactInternalComponent._currentElement.props) || {};
}
if (node && node._currentElement) {
return (node._currentElement.props) || {};
}
if (REACT15 && node) {
if (internalInstance(node) && internalInstance(node)._currentElement) {
return (internalInstance(node)._currentElement.props) || {};
Expand Down
24 changes: 24 additions & 0 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,30 @@ describeWithDOM('mount', () => {
));
expect(foundNotSpan).to.have.length(0);
});

it('should return props object when props() is called', () => {
const SFC = function SFC({ data }) {
return (
<div data-foo={data}>Test SFC</div>
);
};

const content = 'blah';
const wrapper = mount(<SFC data={content} />);
expect(wrapper.props()).to.deep.equal({ data: content });
});

it('should return shallow rendered string when debug() is called', () => {
const SFC = function SFC({ data }) {
return (
<div data-foo={data}>Test SFC</div>
);
};

const content = 'blah';
const wrapper = mount(<SFC data={content} />);
expect(wrapper.debug()).to.equal('<SFC data="' + content + '">\n <div data-foo="' + content + '">\n Test SFC\n </div>\n</SFC>');
});
});

it('should not pass in null or false nodes', () => {
Expand Down

0 comments on commit 363c393

Please sign in to comment.