Skip to content

Commit

Permalink
Fix test, revert unneeded freezeFetch() change.
Browse files Browse the repository at this point in the history
  • Loading branch information
techanvil committed Jan 6, 2025
1 parent 62fe359 commit 7cea708
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,10 @@ describe( 'PropertyOrWebDataStreamNotAvailableError', () => {
} );

it( 'should not render when properties are not loaded yet', async () => {
/*
* The `GET:account-summaries` request is made twice in the test, the second time is from
* when the component is rerendered and the new `getPropertySummaries()` resolver is
* triggered again due to it not yet being resolved because the first request is
* still in flight.
*
* In the happy path in the browser, the request is only made once.
*
* TODO: Check if the component is also rerendered twice in the test on `develop`,
* and also take a look in the browser with a delayed request.
*/
freezeFetch(
new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/account-summaries'
),
{ times: 2 }
)
);

registry
Expand All @@ -97,6 +85,16 @@ describe( 'PropertyOrWebDataStreamNotAvailableError', () => {

expect( container ).toBeEmptyDOMElement();

fetchMock.getOnce(
new RegExp(
'^/google-site-kit/v1/modules/analytics-4/data/account-summaries'
),
{
body: fixtures.accountSummaries,
status: 200,
}
);

await waitForRegistry();
} );

Expand Down
10 changes: 4 additions & 6 deletions tests/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,11 @@ export const muteFetch = ( matcher, response = {} ) => {
* @since 1.12.0
* @private
*
* @param {(string|RegExp|Function|URL|Object)} matcher Criteria for deciding which requests to mock.
* (@link https://www.wheresrhys.co.uk/fetch-mock/#api-mockingmock_matcher)
* @param {Object} [options] Optional. Additional options for the mock.
* @param {number} [options.times] Optional. Number of times to mock the request. Defaults to 1.
* @param {(string|RegExp|Function|URL|Object)} matcher Criteria for deciding which requests to mock.
* (@link https://www.wheresrhys.co.uk/fetch-mock/#api-mockingmock_matcher)
*/
export const freezeFetch = ( matcher, { times = 1 } = {} ) => {
fetchMock.mock( matcher, new Promise( () => {} ), { repeat: times } );
export const freezeFetch = ( matcher ) => {
fetchMock.once( matcher, new Promise( () => {} ) );
};

/**
Expand Down

0 comments on commit 7cea708

Please sign in to comment.