Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[React18] Migrate test suites to account for testing library upgrades kibana-management #201146

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('NumberInput', () => {
expect(input).toBeDisabled();
});

it('recovers if value is null', () => {
it('recovers if value is null', async () => {
const { getByTestId } = render(
wrap(<NumberInput {...defaultProps} field={{ ...defaultProps.field, defaultValue: null }} />)
);
const input = getByTestId(`${TEST_SUBJ_PREFIX_FIELD}-${id}`);
waitFor(() => expect(input).toHaveValue(undefined));

await waitFor(() => expect(getByTestId(`${TEST_SUBJ_PREFIX_FIELD}-${id}`)).toHaveValue(null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know why we need to change the assertion from undefined to null? 🤔

Copy link
Contributor Author

@eokoneyo eokoneyo Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sabarasaba, I suppose actually awaiting the promise from waitFor causes the component to fully render, hence the defaultValue gets set.

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/

import { createMemoryHistory } from 'history';
import { renderHook, act, cleanup } from '@testing-library/react-hooks';

import { renderHook, act, cleanup, waitFor } from '@testing-library/react';

import { coreMock } from '@kbn/core/public/mocks';
import { CoreScopedHistory } from '@kbn/core/public';
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('useUnsavedChangesPrompt', () => {
act(() => history.push('/test'));

// needed because we have an async useEffect
await act(() => new Promise((resolve) => resolve()));
await waitFor(() => new Promise((resolve) => resolve(null)));

expect(navigateToUrl).toBeCalledWith('/mock/test', expect.anything());
expect(coreStart.overlays.openConfirm).toBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { renderHook, act } from '@testing-library/react-hooks';
import { renderHook, act } from '@testing-library/react';
import { useSetInitialValue } from './use_set_initial_value';
import { IToasts } from '@kbn/core-notifications-browser';
import { decompressFromEncodedURIComponent } from 'lz-string';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';

import { useComponentTemplatesContext } from '../../component_templates_context';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { useStepFromQueryString } from './use_step_from_query_string';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { CustomInferenceEndpointConfig, SemanticTextField } from '../../../../../types';
import { useSemanticText } from './use_semantic_text';
import { act } from 'react-dom/test-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { coreMock } from '@kbn/core/public/mocks';
import { createMemoryHistory } from 'history';
import { useRedirectPath } from './redirect_path';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { NormalizedFields } from '../application/components/mappings_editor/types';
import { useDetailsPageMappingsModelManagement } from './use_details_page_mappings_model_management';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { useRedirectPath } from './redirect_path';
import { useKibana } from '../../shared_imports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';

import { useCollapsibleList } from './use_collapsible_list';

Expand Down