From cb14bc4d7f77e966527b537f360e00812a4fb6fd Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Sat, 6 Apr 2019 08:50:37 -0400 Subject: [PATCH] more test coverage (without controls) --- .../data/src/namespace-store/test/index.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/data/src/namespace-store/test/index.js b/packages/data/src/namespace-store/test/index.js index 55dcba9968afff..0865c3f4d31d14 100644 --- a/packages/data/src/namespace-store/test/index.js +++ b/packages/data/src/namespace-store/test/index.js @@ -81,7 +81,7 @@ describe( 'controls', () => { registry.select( 'store' ).getItems(); } ); describe( 'various action types have expected response and resolve as ' + - 'expected', () => { + 'expected with controls middleware', () => { const actions = { *withPromise() { yield { type: 'SOME_ACTION' }; @@ -135,4 +135,35 @@ describe( 'controls', () => { expect( registry.dispatch( 'store' ).normal() ).toBeUndefined(); } ); } ); + describe( 'action type resolves as expected with just promise ' + + 'middleware', () => { + const actions = { + normal: () => ( { type: 'NORMAL' } ), + withPromiseAndAction: () => new Promise( + ( resolve ) => resolve( { type: 'WITH_PROMISE' } ) + ), + withPromiseAndNonAction: () => new Promise( + ( resolve ) => resolve( 10 ) + ), + }; + beforeEach( () => { + registry.registerStore( 'store', { + reducer: () => {}, + actions, + } ); + } ); + it( 'normal action returns undefined', () => { + expect( registry.dispatch( 'store' ).normal() ).toBeUndefined(); + } ); + it( 'action with promise resolving to action returning undefined', () => { + expect( registry.dispatch( 'store' ).withPromiseAndAction() ) + .resolves + .toBeUndefined(); + } ); + it( 'action with promise returning non action throws error', () => { + const dispatchedAction = registry.dispatch( 'store' ) + .withPromiseAndNonAction(); + expect( dispatchedAction ).resolves.toBe( 10 ); + } ); + } ); } );