Skip to content

Commit

Permalink
Add tests for request which include data
Browse files Browse the repository at this point in the history
  • Loading branch information
lipemat committed Sep 7, 2024
1 parent 1722296 commit a14eeac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions jest/tests/util/request-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ describe( 'request-handler.ts', () => {
} );


it( 'Included data in a GET request', async () => {
await wpapi().posts().get( {per_page: 10} );
expect( fetch ).toHaveBeenCalledWith( 'https://example.com/wp/v2/posts?per_page=10&_locale=user', {
body: undefined,
credentials: 'include',
headers: {
Accept: 'application/json, */*;q=0.1',
},
method: 'GET',
} );
} );


it( 'Included data in a POST request', async () => {
await wpapi().posts().create( {title: 'Hello, world!'} );
expect( fetch ).toHaveBeenCalledWith( 'https://example.com/wp/v2/posts?_locale=user', {
body: '{"title":"Hello, world!"}',
credentials: 'include',
headers: {
Accept: 'application/json, */*;q=0.1',
'Content-Type': 'application/json',
},
method: 'POST',
} );
} );


it( 'Uses a root URL', async () => {
setRootURL( 'https://example.com' );
await wpapi().posts().get();
Expand Down

0 comments on commit a14eeac

Please sign in to comment.