Skip to content

Commit

Permalink
Add tests, including one failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 26, 2023
1 parent 91a268d commit 87a9833
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/data/src/test/privateAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { createRegistry } from '../registry';
import createReduxStore from '../redux-store';
import { unlock } from '../private-apis';
import { createRegistrySelector } from '../factory';

describe( 'Private data APIs', () => {
let registry;
Expand Down Expand Up @@ -164,6 +165,43 @@ describe( 'Private data APIs', () => {
);
expect( subPrivateSelectors.getSecretDiscount() ).toEqual( 800 );
} );

it( 'should support registry selectors', () => {
const groceryStore = createStore();
const otherStore = createReduxStore( 'other', {
reducer: ( state = {} ) => state,
} );
registry.register( otherStore );
unlock( otherStore ).registerPrivateSelectors( {
getPrice: createRegistrySelector(
( select ) => () => select( groceryStore ).getPublicPrice()
),
} );
const privateSelectors = unlock( registry.select( otherStore ) );
expect( privateSelectors.getPrice() ).toEqual( 1000 );
} );

it( 'should support calling a private registry selector from a public selector', () => {
const groceryStore = createStore();
const storeA = createReduxStore( 'a', {
reducer: ( state = {} ) => state,
} );
registry.register( storeA );
const getPrice = createRegistrySelector(
( select ) => () => select( groceryStore ).getPublicPrice()
);
unlock( storeA ).registerPrivateSelectors( {
getPrice,
} );
const storeB = createReduxStore( 'b', {
reducer: ( state = {} ) => state,
selectors: {
getPrice: ( state ) => getPrice( state ),
},
} );
registry.register( storeB );
expect( registry.select( storeB ).getPrice() ).toEqual( 1000 );
} );
} );

describe( 'private actions', () => {
Expand Down

0 comments on commit 87a9833

Please sign in to comment.