Skip to content

Commit

Permalink
Leave timeout for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Apr 21, 2024
1 parent 7416e69 commit e985deb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/data/src/redux-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ function mapSelectorWithResolver(

queue.push( [ startResolution, fulfillResolution ] );

window.queueMicrotask( () => {
setTimeout( () => {
if ( queue.length ) {
// Many resolvers can be called at once. The point of this is to
// at least batch `startResolution` actions all together.
Expand All @@ -666,7 +666,7 @@ function mapSelectorWithResolver(

queue.length = 0;
}
} );
}, 0 );
}

const selectorResolver = ( ...args ) => {
Expand Down
25 changes: 14 additions & 11 deletions packages/data/src/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe( 'createRegistry', () => {
expect( registry.select( 'demo' ).getValue() ).toBe( 'OK' );
} );

it( 'should behave as a side effect for the given selector, with arguments', async () => {
it( 'should behave as a side effect for the given selector, with arguments', () => {
const resolver = jest.fn();
registry.registerStore( 'demo', {
reducer: ( state = 'OK' ) => state,
Expand All @@ -263,14 +263,14 @@ describe( 'createRegistry', () => {
} );

const value = registry.select( 'demo' ).getValue( 'arg1', 'arg2' );
jest.runAllTimers();
expect( value ).toBe( 'OK' );
await new Promise( process.nextTick );
expect( resolver ).toHaveBeenCalledWith( 'arg1', 'arg2' );
registry.select( 'demo' ).getValue( 'arg1', 'arg2' );
await new Promise( process.nextTick );
jest.runAllTimers();
expect( resolver ).toHaveBeenCalledTimes( 1 );
registry.select( 'demo' ).getValue( 'arg3', 'arg4' );
await new Promise( process.nextTick );
jest.runAllTimers();
expect( resolver ).toHaveBeenCalledTimes( 2 );
} );

Expand All @@ -287,10 +287,11 @@ describe( 'createRegistry', () => {
} );

const value = registry.select( 'demo' ).getValue( 'arg1', 'arg2' );
jest.runAllTimers();
expect( value ).toBe( 'OK' );
} );

it( 'should use isFulfilled definition before calling the side effect', async () => {
it( 'should use isFulfilled definition before calling the side effect', () => {
const fulfill = jest.fn().mockImplementation( ( state, page ) => {
return { type: 'SET_PAGE', page, result: [] };
} );
Expand Down Expand Up @@ -322,29 +323,31 @@ describe( 'createRegistry', () => {

store.dispatch( { type: 'SET_PAGE', page: 4, result: [] } );
registry.select( 'demo' ).getPage( 1 );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 2 );

await new Promise( process.nextTick );
jest.runAllTimers();

expect( fulfill ).toHaveBeenCalledTimes( 2 );

registry.select( 'demo' ).getPage( 1 );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 2 );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 3, {} );

await new Promise( process.nextTick );
jest.runAllTimers();

// Expected: First and second page fulfillments already triggered, so
// should only be one more than previous assertion set.
expect( fulfill ).toHaveBeenCalledTimes( 3 );

registry.select( 'demo' ).getPage( 1 );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 2 );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 3, {} );
jest.runAllTimers();
registry.select( 'demo' ).getPage( 4 );

await new Promise( process.nextTick );

// Expected:
// - Fourth page was pre-filled. Necessary to determine via
// isFulfilled, but fulfillment resolver should not be triggered.
Expand Down

0 comments on commit e985deb

Please sign in to comment.