Skip to content

Commit 0cb8efe

Browse files
committed
Increase timeout for waitFor in tests to improve reliability
1 parent 4082326 commit 0cb8efe

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

apps/console/src/__tests__/BrowserSimulation.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Console Application Simulation', () => {
143143
// Verify Object Header
144144
await waitFor(() => {
145145
expect(screen.getByRole('heading', { name: /Kitchen Sink/i })).toBeInTheDocument();
146-
});
146+
}, { timeout: 5000 });
147147

148148
// Verify "New" Button exists
149149
const newButton = screen.getByRole('button', { name: /New/i });

apps/console/src/__tests__/ObjectFormTypeMapping.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('ObjectForm Field Type Mapping', () => {
8080
// Wait for schema to load and render
8181
await waitFor(() => {
8282
expect(screen.getByLabelText(/Text Field/i)).toBeInTheDocument();
83-
});
83+
}, { timeout: 3000 });
8484

8585
// 1. Text Field -> Input[type=text]
8686
expect(container.querySelector('input[name="text_field"][type="text"]')).toBeInTheDocument();

apps/console/src/__tests__/ObjectView.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
2-
import React from 'react';
32
import { render, screen, fireEvent } from '@testing-library/react';
43
import '@testing-library/jest-dom';
54
import { ObjectView } from '../components/ObjectView';
@@ -20,7 +19,7 @@ vi.mock('@object-ui/plugin-calendar', () => ({
2019

2120
vi.mock('@object-ui/components', async (importOriginal) => {
2221
const React = await import('react');
23-
const MockTabsContext = React.createContext({ onValueChange: (v: any) => {} });
22+
const MockTabsContext = React.createContext({ onValueChange: ( _v: any) => {} });
2423
const actual = await importOriginal<any>();
2524
return {
2625
...actual,

packages/plugin-form/src/ObjectForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
5858
schema,
5959
dataSource,
6060
}) => {
61+
6162
const [objectSchema, setObjectSchema] = useState<any>(null);
6263
const [formFields, setFormFields] = useState<FormField[]>([]);
6364
const [initialData, setInitialData] = useState<any>(null);
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import { describe, it, expect, vi } from 'vitest';
1+
import { vi, describe, it, expect, beforeEach } from 'vitest';
22
import { render, screen } from '@testing-library/react';
33
import React from 'react';
4-
import { ObjectGridRenderer } from './index';
54
import { SchemaRendererProvider } from '@object-ui/react';
6-
7-
// Mock dependencies
8-
vi.mock('./ObjectGrid', () => ({
9-
ObjectGrid: ({ dataSource }: any) => (
10-
<div data-testid="grid-mock">
11-
{dataSource ? `DataSource: ${dataSource.type}` : 'No DataSource'}
12-
</div>
13-
)
14-
}));
5+
import * as ObjectGridModule from './ObjectGrid';
6+
import { ObjectGridRenderer } from './index';
157

168
describe('Plugin Grid Registration', () => {
17-
it('renderer passes dataSource from context', () => {
18-
9+
it('renderer passes dataSource from context', async () => {
10+
// Spy and mock implementation
11+
vi.spyOn(ObjectGridModule, 'ObjectGrid').mockImplementation(
12+
(({ dataSource }: any) => (
13+
<div data-testid="grid-mock">
14+
{dataSource ? `DataSource: ${dataSource.type}` : 'No DataSource'}
15+
</div>
16+
)) as any
17+
);
18+
1919
render(
2020
<SchemaRendererProvider dataSource={{ type: 'mock-datasource' } as any}>
2121
<ObjectGridRenderer schema={{ type: 'object-grid' }} />
2222
</SchemaRendererProvider>
2323
);
24-
expect(screen.getByTestId('grid-mock')).toHaveTextContent('DataSource: mock-datasource');
24+
25+
// Use findByTestId for async safety
26+
const element = await screen.findByTestId('grid-mock');
27+
expect(element).toHaveTextContent('DataSource: mock-datasource');
2528
});
2629
});

0 commit comments

Comments
 (0)