From 5261ac2e73e58479117fa100d3308eb602e18306 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Wed, 17 Jun 2020 06:03:40 -0400 Subject: [PATCH] Tests: Prevent UnhandledPromiseRejectionWarning in tests (https://github.com/woocommerce/woocommerce-admin/pull/4605) --- .../components/src/plugins/test/index.js | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce-admin/packages/components/src/plugins/test/index.js b/plugins/woocommerce-admin/packages/components/src/plugins/test/index.js index 4ba51bd9fa8..609b96b6215 100644 --- a/plugins/woocommerce-admin/packages/components/src/plugins/test/index.js +++ b/plugins/woocommerce-admin/packages/components/src/plugins/test/index.js @@ -11,32 +11,45 @@ import { Button } from '@wordpress/components'; import { Plugins } from '../index.js'; 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( {} } + onComplete={ onComplete } + installAndActivatePlugins={ installAndActivatePlugins } + createNotice={ createNotice } /> ); - const buttons = pluginsWrapper.find( Button ); + const buttons = pluginsWrapper.find( Button ); 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 continueButton = pluginsWrapper.find( Button ); expect( continueButton.length ).toBe( 1 ); 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 buttons = pluginsWrapper.find( Button ); expect( buttons.length ).toBe( 2 ); expect( buttons.at( 0 ).text() ).toBe( 'Install & enable' ); @@ -68,7 +81,9 @@ describe( 'Installing and activating', () => { const installButton = pluginsWrapper.find( Button ).at( 0 ); installButton.simulate( 'click' ); - expect( installAndActivatePlugins ).toHaveBeenCalledWith( [ 'jetpack' ] ); + expect( installAndActivatePlugins ).toHaveBeenCalledWith( [ + 'jetpack', + ] ); } ); it( 'should call the onComplete callback', async () => {