Skip to content

Commit

Permalink
more test coverage (without controls)
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Apr 6, 2019
1 parent 88b81e4 commit cb14bc4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/data/src/namespace-store/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand Down Expand Up @@ -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 );
} );
} );
} );

0 comments on commit cb14bc4

Please sign in to comment.