From 998658d5e0bb8cc0191d13a82472f1ffaf86fc6b Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Mon, 3 Jul 2023 16:52:31 +0200 Subject: [PATCH] fix some unit tests --- client/lib/signup/test/get-new-site-params.ts | 4 +- .../wpcom/gravatar-upload/test/index.js | 18 ++++----- .../test/create-transient-media-items.js | 38 ++++++++++++------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/client/lib/signup/test/get-new-site-params.ts b/client/lib/signup/test/get-new-site-params.ts index 3c431a4a96f38e..4ea7bb5f19c0c0 100644 --- a/client/lib/signup/test/get-new-site-params.ts +++ b/client/lib/signup/test/get-new-site-params.ts @@ -6,12 +6,14 @@ describe( 'get-new-site-params', () => { dependencies: {}, flowToCheck: 'myFlow', } ); + expect( options ).toHaveProperty( 'site_creation_flow', 'myFlow' ); expect( options ).toHaveProperty( 'use_theme_annotation', false ); expect( options ).toHaveProperty( 'default_annotation_as_primary_fallback', true ); expect( options ).toHaveProperty( 'designType', undefined ); - expect( options ).toHaveProperty( 'site_segment', undefined ); expect( options ).toHaveProperty( 'wpcom_public_coming_soon', 1 ); + + expect( options ).not.toHaveProperty( 'site_segment' ); } ); describe( 'For preselected url', () => { diff --git a/client/state/data-layer/wpcom/gravatar-upload/test/index.js b/client/state/data-layer/wpcom/gravatar-upload/test/index.js index 5213783bb02538..385ab41d6f7f68 100644 --- a/client/state/data-layer/wpcom/gravatar-upload/test/index.js +++ b/client/state/data-layer/wpcom/gravatar-upload/test/index.js @@ -35,17 +35,17 @@ describe( '#uploadGravatar()', () => { } ); describe( '#announceSuccess()', () => { - let oFormData; - let oFileReader; const noop = () => {}; const tempImageSrc = 'tempImageSrc'; beforeAll( () => { - oFormData = global.FormData; - oFileReader = global.FileReader; - global.FormData = jest.fn( () => ( { - append: noop, - } ) ); + Object.defineProperty( + global, + 'FormData', + jest.fn( () => ( { + append: noop, + } ) ) + ); global.FileReader = jest.fn( () => ( { readAsDataURL: noop, addEventListener: function ( event, callback ) { @@ -54,10 +54,6 @@ describe( '#announceSuccess()', () => { }, } ) ); } ); - afterAll( () => { - global.FormData = oFormData; - global.FileReader = oFileReader; - } ); test( 'dispatches a success action when the file is read', () => { const action = { diff --git a/client/state/media/thunks/test/create-transient-media-items.js b/client/state/media/thunks/test/create-transient-media-items.js index cfa9a112f90d8b..22fa0f746f43d9 100644 --- a/client/state/media/thunks/test/create-transient-media-items.js +++ b/client/state/media/thunks/test/create-transient-media-items.js @@ -64,9 +64,12 @@ describe( 'media - thunks - createTransientMediaItems', () => { // upon failure we return undefined for that file rather than throwing expect( createTransientMediaItems( [ file ], site ) ).toEqual( [ undefined ] ); - expect( validateMediaItem ).toHaveBeenCalledWith( site, { - ...file, - } ); + expect( validateMediaItem ).toHaveBeenCalledWith( + site, + expect.objectContaining( { + ...file, + } ) + ); expect( setMediaItemErrors ).toHaveBeenCalledWith( siteId, transientId, errors ); } ); @@ -79,9 +82,12 @@ describe( 'media - thunks - createTransientMediaItems', () => { createTransientMediaItems( [ file ], site ); - expect( validateMediaItem ).toHaveBeenCalledWith( site, { - ...file, - } ); + expect( validateMediaItem ).toHaveBeenCalledWith( + site, + expect.objectContaining( { + ...file, + } ) + ); expect( setMediaItemErrors ).not.toHaveBeenCalled(); } ); @@ -98,9 +104,12 @@ describe( 'media - thunks - createTransientMediaItems', () => { createTransientMediaItems( [ fileWithoutPassedInId ], site ); - expect( createMediaItem ).toHaveBeenCalledWith( site, { - ID: generatedId, - } ); + expect( createMediaItem ).toHaveBeenCalledWith( + site, + expect.objectContaining( { + ID: generatedId, + } ) + ); } ); it( 'should override the generated transient ID with the one passed in', () => { @@ -110,10 +119,13 @@ describe( 'media - thunks - createTransientMediaItems', () => { createTransientMediaItems( [ file ], site ); - expect( createMediaItem ).toHaveBeenCalledWith( site, { - ...file, - ID: passedInId, - } ); + expect( createMediaItem ).toHaveBeenCalledWith( + site, + expect.objectContaining( { + ...file, + ID: passedInId, + } ) + ); } ); } ); } );