Skip to content

Commit

Permalink
Migrate to snapshot testing with react-test-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 30, 2018
1 parent f90bf36 commit 4c4a70e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
17 changes: 17 additions & 0 deletions packages/components/src/slot-fill/test/__snapshots__/slot.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,20 @@ exports[`Slot should render a string Fill with HTML wrapper when render props us
exports[`Slot should render empty Fills 1`] = `<div />`;

exports[`Slot should render empty Fills without HTML wrapper when render props used 1`] = `<div />`;

exports[`Slot should render in expected order 1`] = `
Array [
<div>
first
second
</div>,
<button
onClick={[Function]}
type="button"
/>,
<button
onClick={[Function]}
type="button"
/>,
]
`;
47 changes: 23 additions & 24 deletions packages/components/src/slot-fill/test/slot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { mount } from 'enzyme';
import { isEmpty } from 'lodash';
import ReactTestRenderer from 'react-test-renderer';

Expand Down Expand Up @@ -171,43 +170,43 @@ describe( 'Slot', () => {
} );

it( 'should render in expected order', () => {
const element = mount(
const testRenderer = ReactTestRenderer.create(
<Provider>
<div key="slot">
<Slot name="egg" />
</div>
</Provider>
);

element.setProps( {
children: [
testRenderer.update(
<Provider>
<div key="slot">
<Slot name="egg" />
</div>,
<Filler name="egg" key="first" text="first" />,
<Filler name="egg" key="second" text="second" />,
],
} );

element.setProps( {
children: [
</div>
<Filler name="egg" key="first" text="first" />
<Filler name="egg" key="second" text="second" />
</Provider>
);

testRenderer.update(
<Provider>
<div key="slot">
<Slot name="egg" />
</div>,
<Filler name="egg" key="second" text="second" />,
],
} );
</div>
<Filler name="egg" key="second" text="second" />
</Provider>
);

element.setProps( {
children: [
testRenderer.update(
<Provider>
<div key="slot">
<Slot name="egg" />
</div>,
<Filler name="egg" key="first" text="first" />,
<Filler name="egg" key="second" text="second" />,
],
} );
</div>
<Filler name="egg" key="first" text="first" />
<Filler name="egg" key="second" text="second" />
</Provider>
);

expect( element.html() ).toBe( '<div>firstsecond</div>' );
expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
} );

0 comments on commit 4c4a70e

Please sign in to comment.