replace usages of await act(async () => {}) with waitFor

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-14 13:59:51 +02:00
parent bfee94f0c5
commit 0696ef1a34
14 changed files with 419 additions and 417 deletions
+15 -15
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import React from 'react';
import { renderHook, act } from '@testing-library/react';
import { renderHook, act, waitFor } from '@testing-library/react';
import { ThemeProvider } from '@material-ui/core';
@@ -140,9 +140,9 @@ describe('useTechDocsReaderPage', () => {
namespace: mockEntityMetadata.metadata.namespace?.toLocaleLowerCase(),
};
const { result } = renderHook(() => useTechDocsReaderPage(), { wrapper });
await act(async () => {});
expect(result.current.entityRef).toStrictEqual(lowercaseEntityRef);
await waitFor(() => {
expect(result.current.entityRef).toStrictEqual(lowercaseEntityRef);
});
});
it('entityRef is not modified when legacyUseCaseSensitiveTripletPaths is true', async () => {
@@ -159,23 +159,23 @@ describe('useTechDocsReaderPage', () => {
config: { techdocs: { legacyUseCaseSensitiveTripletPaths: true } },
}),
});
await act(async () => {});
expect(result.current.entityRef).toStrictEqual(caseSensitiveEntityRef);
await waitFor(() => {
expect(result.current.entityRef).toStrictEqual(caseSensitiveEntityRef);
});
});
it('entityRef provided as analytics context', async () => {
renderHook(() => useAnalytics().captureEvent('action', 'subject'), {
wrapper,
});
await act(async () => {});
expect(analyticsApiMock.getEvents()[0]).toMatchObject({
action: 'action',
subject: 'subject',
context: {
entityRef: 'component:default/test',
},
await waitFor(() => {
expect(analyticsApiMock.getEvents()[0]).toMatchObject({
action: 'action',
subject: 'subject',
context: {
entityRef: 'component:default/test',
},
});
});
});
});