Skip to content

Commit

Permalink
API Fetch: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed May 22, 2020
1 parent c5bebcc commit d6e69ab
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/api-fetch/src/middlewares/test/fetch-all-middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
* Internal dependencies
*/
import fetchAllMiddleware from '../fetch-all-middleware';

describe( 'Fetch All Middleware', () => {
beforeEach( jest.resetModules );

it( 'should defer with the same options to the next middleware', async () => {
expect.hasAssertions();
const originalOptions = { path: '/posts' };
Expand All @@ -12,14 +9,17 @@ describe( 'Fetch All Middleware', () => {
return Promise.resolve( 'ok' );
};

await fetchAllMiddleware( originalOptions, next );
await require( '../fetch-all-middleware' ).default(
originalOptions,
next
);
} );

it( 'should paginate the request', async () => {
expect.hasAssertions();
const originalOptions = { url: '/posts?per_page=-1' };
let counter = 1;
const next = ( options ) => {
jest.doMock( '../../index.js', () => ( options ) => {
if ( counter === 1 ) {
expect( options.url ).toBe( '/posts?per_page=100' );
} else {
Expand All @@ -42,9 +42,11 @@ describe( 'Fetch All Middleware', () => {
counter++;

return response;
};

const result = await fetchAllMiddleware( originalOptions, next );
} );
const result = await require( '../fetch-all-middleware' ).default(
originalOptions,
() => {}
);

expect( result ).toEqual( [ 'item', 'item' ] );
} );
Expand Down

0 comments on commit d6e69ab

Please sign in to comment.