From 4f630b18f26d230c7dd606e78f69fa56a441ccd9 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 2 Aug 2018 16:08:21 -0400 Subject: [PATCH] Data: Add tests for WPDataRegistry#use --- packages/data/src/test/registry.js | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/data/src/test/registry.js b/packages/data/src/test/registry.js index acc26dc607978e..2e4223ca52afed 100644 --- a/packages/data/src/test/registry.js +++ b/packages/data/src/test/registry.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { castArray } from 'lodash'; +import { castArray, mapValues } from 'lodash'; /** * Internal dependencies @@ -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', () => {