Skip to content

Commit 1018ab2

Browse files
replace named imports with explicit «React» references in mocks
Update mocked components and hooks to use explicit «React» references instead of named imports. This change ensures compatibility with Jest's module mocking and avoids potential conflicts with React's internal APIs. Additionally, replace JSX syntax with «React.createElement» in the mocked «MockModelForm» for consistency and clarity in the mock's implementation.
1 parent 70e7ed1 commit 1018ab2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

public/dashboard-assistant/components/__tests__/model-register.test.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React, { useState, useCallback, useEffect } from 'react';
6+
import React from 'react';
77
import userEvent from '@testing-library/user-event';
88
import { render, screen, waitFor } from '../../../../test/test_utils';
9-
import { ExecutionState } from '../../modules/installation-manager/domain';
109

1110
jest.mock('../model-form', () => {
11+
const _React = jest.requireActual<typeof import('react')>('react');
12+
1213
const MockModelForm = ({ onChange, onValidationChange }: any) => {
13-
useEffect(() => {
14+
_React.useEffect(() => {
1415
onChange?.({
1516
modelProvider: 'OpenAI',
1617
model: 'gpt-4o',
@@ -20,7 +21,7 @@ jest.mock('../model-form', () => {
2021
onValidationChange?.(true);
2122
}, [onChange, onValidationChange]);
2223

23-
return <div data-testid="mock-model-form" />;
24+
return _React.createElement('div', { 'data-testid': 'mock-model-form' });
2425
};
2526

2627
return {
@@ -30,6 +31,11 @@ jest.mock('../model-form', () => {
3031
});
3132

3233
jest.mock('../../modules/installation-manager/hooks/use-assistant-installation', () => {
34+
const React = jest.requireActual<typeof import('react')>('react');
35+
const { ExecutionState } = jest.requireActual<
36+
typeof import('../../modules/installation-manager/domain')
37+
>('../../modules/installation-manager/domain');
38+
3339
const failedStep = {
3440
stepName: 'Create Model',
3541
state: ExecutionState.FAILED,
@@ -54,9 +60,9 @@ jest.mock('../../modules/installation-manager/hooks/use-assistant-installation',
5460
return {
5561
__esModule: true,
5662
useAssistantInstallation: () => {
57-
const [error, setError] = useState<string | undefined>(undefined);
63+
const [error, setError] = React.useState<string | undefined>(undefined);
5864

59-
const install = useCallback(async () => {
65+
const install = React.useCallback(async () => {
6066
setError('Steps: "Create Model" has failed');
6167
}, []);
6268

0 commit comments

Comments
 (0)