Skip to content

Commit

Permalink
Data: Add tests for WPDataRegistry#use
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Aug 3, 2018
1 parent 8f8c544 commit 4f630b1
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/data/src/test/registry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { castArray } from 'lodash';
import { castArray, mapValues } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -472,6 +472,41 @@ describe( 'createRegistry', () => {
expect( store.getState() ).toBe( 5 );
} );
} );

describe( 'use', () => {
it( 'should pass through options object to plugin', () => {
const expectedOptions = {};
let actualOptions;

function plugin( _registry, options ) {
// The registry passed to a plugin is not the same as the one
// returned by createRegistry, as the former uses the internal
// representation of the object, the latter applying its
// function proxying.
expect( _registry ).toMatchObject(
mapValues( registry, () => expect.any( Function ) )
);

actualOptions = options;

return {};
}

registry.use( plugin, expectedOptions );

expect( actualOptions ).toBe( expectedOptions );
} );

it( 'should override base method', () => {
function plugin( _registry, options ) {
return { select: () => options.value };
}

registry.use( plugin, { value: 10 } );

expect( registry.select() ).toBe( 10 );
} );
} );
} );

describe( 'isActionLike', () => {
Expand Down

0 comments on commit 4f630b1

Please sign in to comment.