Skip to content

Commit

Permalink
fix some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flootr committed Jul 4, 2023
1 parent 79259c1 commit 998658d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
4 changes: 3 additions & 1 deletion client/lib/signup/test/get-new-site-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
18 changes: 7 additions & 11 deletions client/state/data-layer/wpcom/gravatar-upload/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 = {
Expand Down
38 changes: 25 additions & 13 deletions client/state/media/thunks/test/create-transient-media-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );

Expand All @@ -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();
}
);
Expand All @@ -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', () => {
Expand All @@ -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,
} )
);
} );
} );
} );

0 comments on commit 998658d

Please sign in to comment.