Skip to content

Commit

Permalink
Add test to cover inifinite re-render loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 15, 2020
1 parent a31f651 commit 3b8b6ea
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,10 @@ describe( 'Default search suggestions', () => {
// when this does not have a value
expect( searchInput.value ).toBe( '' );

expect( searchSuggestionsSpy ).toHaveBeenCalled();
// Ensure only called once as a guard against potential infinite
// re-render loop within `componentDidUpdate` calling `updateSuggestions`
// which has calls to `setState` within it.
expect( searchSuggestionsSpy ).toHaveBeenCalledTimes( 1 );

// Verify the search results already display the initial suggestions
expect( initialSearchResultElements ).toHaveLength( expectedResultsLength );
Expand Down Expand Up @@ -396,7 +399,10 @@ describe( 'Default search suggestions', () => {

expect( searchResultElements ).toHaveLength( 3 );

expect( searchSuggestionsSpy ).toHaveBeenCalled();
// Ensure only called once as a guard against potential infinite
// re-render loop within `componentDidUpdate` calling `updateSuggestions`
// which has calls to `setState` within it.
expect( searchSuggestionsSpy ).toHaveBeenCalledTimes( 1 );
} );
} );

Expand Down

0 comments on commit 3b8b6ea

Please sign in to comment.