Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mountToJson not rendering mixed children #34

Merged
merged 2 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function instToJson(inst) {
if (typeof inst === 'string' || typeof inst === 'number') return inst;
if (!inst) return '';

if (inst._stringText) {
return inst._stringText;
}

if (!inst.getPublicInstance) {
const internal = internalInstance(inst);
return instToJson(internal);
Expand Down
40 changes: 40 additions & 0 deletions tests/core/__snapshots__/mount.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,46 @@ exports[`test converts basic pure mount 1`] = `
</BasicPure>
`;

exports[`test converts class mount with mixed children 1`] = `
<BasicClass>
<div
className="basic-class undefined"
onClick={[Function]}>
<div
className="group"
id="group-id">
<span>
Hello
world
!
</span>
<span
className="empty" />
</div>
</div>
</BasicClass>
`;

exports[`test converts pure mount with mixed children 1`] = `
<BasicPure>
<div
className="basic-pure undefined"
onClick={[Function]}>
<div
className="group"
id="group-id">
<span>
Hello
world
!
</span>
<span
className="empty" />
</div>
</div>
</BasicPure>
`;

exports[`test skips undefined props 1`] = `
<BasicWithUndefined>
<button>
Expand Down
14 changes: 14 additions & 0 deletions tests/core/mount.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ it('converts basic pure mount', () => {
expect(mountToJson(mounted)).toMatchSnapshot();
});

it('converts pure mount with mixed children', () => {
const mounted = mount(
<BasicPure>Hello {'world'}!</BasicPure>
);
expect(mountToJson(mounted)).toMatchSnapshot();
});

it('converts basic class mount', () => {
const mounted = mount(
<BasicClass className="class"><strong>Hello!</strong></BasicClass>
Expand All @@ -22,6 +29,13 @@ it('converts basic class mount', () => {
expect(mountToJson(mounted)).toMatchSnapshot();
});

it('converts class mount with mixed children', () => {
const mounted = mount(
<BasicClass>Hello {'world'}!</BasicClass>
);
expect(mountToJson(mounted)).toMatchSnapshot();
});

it('converts a class mount with a pure function in it', () => {
const mounted = mount(
<ClassWithPure className="class"><strong>Hello!</strong></ClassWithPure>
Expand Down