Skip to content

Commit

Permalink
fix: mountToJson not rendering mixed children (#34)
Browse files Browse the repository at this point in the history
* Fix mountToJson not rendering string text

* fixup! Fix mountToJson not rendering string text
  • Loading branch information
prayogoa authored and adriantoine committed Dec 15, 2016
1 parent 0575ada commit 4fcfbf3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
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

0 comments on commit 4fcfbf3

Please sign in to comment.