Tests: Prevent UnhandledPromiseRejectionWarning in tests (https://github.com/woocommerce/woocommerce-admin/pull/4605)

This commit is contained in:
Matt Sherman 2020-06-17 06:03:40 -04:00 committed by GitHub
parent f71706d4f4
commit 5261ac2e73
1 changed files with 21 additions and 6 deletions

View File

@ -11,32 +11,45 @@ import { Button } from '@wordpress/components';
import { Plugins } from '../index.js'; import { Plugins } from '../index.js';
describe( 'Rendering', () => { describe( 'Rendering', () => {
it( 'should render nothing when autoInstalling', () => { it( 'should render nothing when autoInstalling', async () => {
const installAndActivatePlugins = jest.fn().mockResolvedValue( {
success: true,
data: {
activated: [ 'jetpack' ],
},
} );
const createNotice = jest.fn();
const onComplete = jest.fn();
const pluginsWrapper = shallow( const pluginsWrapper = shallow(
<Plugins <Plugins
autoInstall autoInstall
pluginSlugs={ [ 'jetpack' ] } pluginSlugs={ [ 'jetpack' ] }
onComplete={ () => {} } onComplete={ onComplete }
installAndActivatePlugins={ installAndActivatePlugins }
createNotice={ createNotice }
/> />
); );
const buttons = pluginsWrapper.find( Button );
const buttons = pluginsWrapper.find( Button );
expect( buttons.length ).toBe( 0 ); expect( buttons.length ).toBe( 0 );
} ); } );
it( 'should render a continue button when no pluginSlugs are given', () => { it( 'should render a continue button when no pluginSlugs are given', async () => {
const pluginsWrapper = shallow( const pluginsWrapper = shallow(
<Plugins pluginSlugs={ [] } onComplete={ () => {} } /> <Plugins pluginSlugs={ [] } onComplete={ () => {} } />
); );
const continueButton = pluginsWrapper.find( Button ); const continueButton = pluginsWrapper.find( Button );
expect( continueButton.length ).toBe( 1 ); expect( continueButton.length ).toBe( 1 );
expect( continueButton.text() ).toBe( 'Continue' ); expect( continueButton.text() ).toBe( 'Continue' );
} ); } );
it( 'should render install and no thanks buttons', () => { it( 'should render install and no thanks buttons', async () => {
const pluginsWrapper = shallow( const pluginsWrapper = shallow(
<Plugins pluginSlugs={ [ 'jetpack' ] } onComplete={ () => {} } /> <Plugins pluginSlugs={ [ 'jetpack' ] } onComplete={ () => {} } />
); );
const buttons = pluginsWrapper.find( Button ); const buttons = pluginsWrapper.find( Button );
expect( buttons.length ).toBe( 2 ); expect( buttons.length ).toBe( 2 );
expect( buttons.at( 0 ).text() ).toBe( 'Install & enable' ); expect( buttons.at( 0 ).text() ).toBe( 'Install & enable' );
@ -68,7 +81,9 @@ describe( 'Installing and activating', () => {
const installButton = pluginsWrapper.find( Button ).at( 0 ); const installButton = pluginsWrapper.find( Button ).at( 0 );
installButton.simulate( 'click' ); installButton.simulate( 'click' );
expect( installAndActivatePlugins ).toHaveBeenCalledWith( [ 'jetpack' ] ); expect( installAndActivatePlugins ).toHaveBeenCalledWith( [
'jetpack',
] );
} ); } );
it( 'should call the onComplete callback', async () => { it( 'should call the onComplete callback', async () => {