Skip to content

Commit

Permalink
Don't mock lodash.uniqueId
Browse files Browse the repository at this point in the history
We can avoid mocking `uniqueId` by being less pedantic about what our
tests expect.
  • Loading branch information
noisysocks committed Jan 4, 2018
1 parent 92b6a18 commit 78a9bb7
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions editor/store/test/effects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import lodash from 'lodash';
import { noop, reduce, set } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -32,8 +32,6 @@ import reducer from '../reducer';
import effects from '../effects';
import * as selectors from '../../store/selectors';

const { noop, reduce, set } = lodash;

// Make all generated UUIDs the same for testing
jest.mock( 'uuid/v4', () => {
return jest.fn( () => 'this-is-a-mock-uuid' );
Expand Down Expand Up @@ -477,8 +475,6 @@ describe( 'effects', () => {

describe( 'reusable block effects', () => {
beforeAll( () => {
lodash.uniqueId = jest.spyOn( lodash, 'uniqueId' );

registerBlockType( 'core/test-block', {
title: 'Test block',
category: 'common',
Expand All @@ -497,13 +493,7 @@ describe( 'effects', () => {
} );
} );

beforeEach( () => {
lodash.uniqueId.mockReset();
} );

afterAll( () => {
lodash.uniqueId.mockRestore();

unregisterBlockType( 'core/test-block' );
unregisterBlockType( 'core/block' );
} );
Expand Down Expand Up @@ -858,26 +848,24 @@ describe( 'effects', () => {
const dispatch = jest.fn();
const store = { getState: () => state, dispatch };

lodash.uniqueId.mockReturnValue( 1 );

handler( convertBlockToReusable( staticBlock.uid ), store );

expect( dispatch ).toHaveBeenCalledWith(
updateReusableBlock( -1, {
id: -1,
updateReusableBlock( expect.any( Number ), {
id: expect.any( Number ),
isTemporary: true,
title: 'Untitled block',
type: staticBlock.name,
attributes: staticBlock.attributes,
} )
);
expect( dispatch ).toHaveBeenCalledWith(
saveReusableBlock( -1 )
saveReusableBlock( expect.any( Number ) )
);
expect( dispatch ).toHaveBeenCalledWith(
replaceBlocks(
[ staticBlock.uid ],
[ createBlock( 'core/block', { ref: -1 } ) ]
[ createBlock( 'core/block', { ref: expect.any( Number ) } ) ]
)
);
} );
Expand Down

0 comments on commit 78a9bb7

Please sign in to comment.