Skip to content

Commit

Permalink
Components: Try alternative approach for spying portal render
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Aug 9, 2017
1 parent d6ac8f9 commit aefc205
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 3 additions & 1 deletion components/popover/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ describe( 'Popover', () => {
} );

it( 'should render into provider context', () => {
const element = require( '@wordpress/element' );
jest.spyOn( element, 'createPortal' );
const target = document.createElement( 'div' );

mount(
Expand All @@ -243,7 +245,7 @@ describe( 'Popover', () => {
</PopoverProvider>
);

expect( target.childElementCount ).toBe( 1 );
expect( element.createPortal.mock.calls[ 0 ][ 1 ] ).toBe( target );
} );
} );
} );
20 changes: 4 additions & 16 deletions test/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ require( 'core-js/modules/es7.object.values' );

// TODO: This is only necessary so long as we're running React 15.x in the Node
// context, since createPortal is only available in 16.x
jest.mock( '@wordpress/element', () => {
const element = require.requireActual( '@wordpress/element' );

return {
...element,
createPortal: ( ...args ) => {
/* eslint-disable no-console */
const consoleWarn = console.error;
// Shhhh...
console.error = () => {};
element.render( ...args );
console.error = consoleWarn;
/* eslint-enable no-console */
},
};
} );
jest.mock( '@wordpress/element', () => ( {
...require.requireActual( '@wordpress/element' ),
createPortal: ( x ) => x,
} ) );

0 comments on commit aefc205

Please sign in to comment.