@copilotkit/react-native 1.57.3 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/USAGE.md +116 -0
  2. package/dist/RenderToolContext-CBNKcJqz.cjs +126 -0
  3. package/dist/RenderToolContext-CBNKcJqz.cjs.map +1 -0
  4. package/dist/RenderToolContext-CszHyes6.mjs +75 -0
  5. package/dist/RenderToolContext-CszHyes6.mjs.map +1 -0
  6. package/dist/components/index.cjs +722 -0
  7. package/dist/components/index.cjs.map +1 -0
  8. package/dist/components/index.d.cts +203 -0
  9. package/dist/components/index.d.mts +203 -0
  10. package/dist/components/index.mjs +714 -0
  11. package/dist/components/index.mjs.map +1 -0
  12. package/dist/index.cjs +53 -38
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +102 -6
  15. package/dist/index.d.mts +100 -4
  16. package/dist/index.mjs +49 -3
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/polyfills/encoding.cjs +1 -1
  19. package/dist/polyfills/streams.cjs +1 -1
  20. package/package.json +24 -4
  21. package/src/CopilotKitProvider.tsx +2 -1
  22. package/src/__mocks__/react-native-streamdown.ts +16 -0
  23. package/src/__mocks__/react-native.ts +52 -0
  24. package/src/__tests__/headless-integration.test.tsx +16 -0
  25. package/src/components/CopilotChat.tsx +465 -0
  26. package/src/components/CopilotModal.tsx +210 -0
  27. package/src/components/Markdown.tsx +124 -0
  28. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +418 -0
  29. package/src/components/__tests__/CopilotChat.test.tsx +390 -0
  30. package/src/components/__tests__/CopilotModal.test.tsx +257 -0
  31. package/src/components/__tests__/Markdown.test.tsx +106 -0
  32. package/src/components/index.ts +18 -0
  33. package/src/components/messages/AssistantMessage.tsx +73 -0
  34. package/src/components/messages/TypingIndicator.tsx +103 -0
  35. package/src/components/messages/UserMessage.tsx +68 -0
  36. package/src/components/messages/__tests__/messages-edge-cases.test.tsx +179 -0
  37. package/src/components/messages/__tests__/messages.test.tsx +189 -0
  38. package/src/components/messages/__tests__/utils.test.ts +39 -0
  39. package/src/components/messages/index.ts +8 -0
  40. package/src/components/messages/utils.ts +11 -0
  41. package/src/hooks/RenderToolContext.tsx +150 -0
  42. package/src/hooks/__tests__/RenderToolContext.test.tsx +264 -0
  43. package/src/hooks/__tests__/useRenderTool.test.tsx +334 -0
  44. package/src/hooks/index.ts +9 -0
  45. package/src/hooks/useRenderTool.ts +96 -0
  46. package/src/index.ts +10 -3
  47. package/tsdown.config.ts +9 -0
  48. package/vitest.config.mjs +10 -0
@@ -0,0 +1,189 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, it, expect, vi } from "vitest";
4
+
5
+ // ─── Mock react-native ───────────────────────────────────────────────────────
6
+ // jsdom doesn't have react-native, so we provide lightweight stand-ins.
7
+ vi.mock("react-native", () => {
8
+ const React = require("react");
9
+
10
+ const View = React.forwardRef(
11
+ (
12
+ {
13
+ children,
14
+ style,
15
+ testID,
16
+ accessibilityLabel,
17
+ accessibilityRole,
18
+ ...rest
19
+ }: any,
20
+ ref: any,
21
+ ) =>
22
+ React.createElement(
23
+ "div",
24
+ {
25
+ ref,
26
+ style,
27
+ "data-testid": testID,
28
+ "aria-label": accessibilityLabel,
29
+ role: accessibilityRole,
30
+ ...rest,
31
+ },
32
+ children,
33
+ ),
34
+ );
35
+ View.displayName = "View";
36
+
37
+ const Text = React.forwardRef(({ children, style, ...rest }: any, ref: any) =>
38
+ React.createElement("span", { ref, style, ...rest }, children),
39
+ );
40
+ Text.displayName = "Text";
41
+
42
+ const AnimatedValue = class {
43
+ _value: number;
44
+ constructor(value: number) {
45
+ this._value = value;
46
+ }
47
+ interpolate({ outputRange }: any) {
48
+ return outputRange[0];
49
+ }
50
+ };
51
+
52
+ const AnimatedView = React.forwardRef(
53
+ ({ children, style, ...rest }: any, ref: any) =>
54
+ React.createElement("div", { ref, style, ...rest }, children),
55
+ );
56
+ AnimatedView.displayName = "Animated.View";
57
+
58
+ const timing = (_value: any, _config: any) => ({
59
+ start: vi.fn(),
60
+ stop: vi.fn(),
61
+ });
62
+
63
+ const sequence = (animations: any[]) => ({
64
+ start: vi.fn(),
65
+ stop: vi.fn(),
66
+ });
67
+
68
+ const loop = (animation: any) => ({
69
+ start: vi.fn(),
70
+ stop: vi.fn(),
71
+ });
72
+
73
+ const parallel = (animations: any[]) => ({
74
+ start: vi.fn(),
75
+ stop: vi.fn(),
76
+ });
77
+
78
+ const delay = (_ms: number) => ({
79
+ start: vi.fn(),
80
+ stop: vi.fn(),
81
+ });
82
+
83
+ const Animated = {
84
+ Value: AnimatedValue,
85
+ View: AnimatedView,
86
+ timing,
87
+ sequence,
88
+ loop,
89
+ parallel,
90
+ delay,
91
+ };
92
+
93
+ const StyleSheet = {
94
+ create: (styles: any) => styles,
95
+ flatten: (style: any) =>
96
+ Array.isArray(style) ? Object.assign({}, ...style) : style || {},
97
+ };
98
+
99
+ return {
100
+ View,
101
+ Text,
102
+ Animated,
103
+ StyleSheet,
104
+ };
105
+ });
106
+
107
+ // ─── Mock the Markdown component (B1 owns it, may not exist yet) ─────────────
108
+ vi.mock("../../Markdown", () => ({
109
+ CopilotMarkdown: ({ content }: { content: string }) => {
110
+ const React = require("react");
111
+ return React.createElement(
112
+ "div",
113
+ { "data-testid": "copilot-markdown" },
114
+ content,
115
+ );
116
+ },
117
+ }));
118
+
119
+ // ─── Imports under test (after mocks) ────────────────────────────────────────
120
+ import { AssistantMessage } from "../AssistantMessage";
121
+ import { UserMessage } from "../UserMessage";
122
+ import { TypingIndicator } from "../TypingIndicator";
123
+
124
+ // ─── Tests ───────────────────────────────────────────────────────────────────
125
+
126
+ describe("AssistantMessage", () => {
127
+ it("renders content via CopilotMarkdown", () => {
128
+ const { getByTestId } = render(
129
+ <AssistantMessage content="Hello from the assistant" />,
130
+ );
131
+ const markdown = getByTestId("copilot-markdown");
132
+ expect(markdown).toBeTruthy();
133
+ expect(markdown.textContent).toBe("Hello from the assistant");
134
+ });
135
+
136
+ it("shows TypingIndicator when isLoading is true", () => {
137
+ const { getByLabelText, queryByTestId } = render(
138
+ <AssistantMessage content="" isLoading />,
139
+ );
140
+ // Typing indicator should be present
141
+ expect(getByLabelText("Typing indicator")).toBeTruthy();
142
+ // Markdown should NOT render during loading
143
+ expect(queryByTestId("copilot-markdown")).toBeNull();
144
+ });
145
+
146
+ it("displays a timestamp when provided", () => {
147
+ const date = new Date(2025, 0, 15, 14, 30); // Jan 15 2025, 2:30 PM
148
+ const { container } = render(
149
+ <AssistantMessage content="Hi" timestamp={date} />,
150
+ );
151
+ expect(container.textContent).toContain("2:30 PM");
152
+ });
153
+
154
+ it("does not display timestamp when not provided", () => {
155
+ const { container } = render(<AssistantMessage content="No timestamp" />);
156
+ // Should only contain the message text (via markdown mock)
157
+ expect(container.textContent).toBe("No timestamp");
158
+ });
159
+ });
160
+
161
+ describe("UserMessage", () => {
162
+ it("renders plain text content", () => {
163
+ const { container } = render(<UserMessage content="Hello from the user" />);
164
+ expect(container.textContent).toContain("Hello from the user");
165
+ });
166
+
167
+ it("displays a timestamp when provided", () => {
168
+ const date = new Date(2025, 5, 20, 9, 5); // Jun 20 2025, 9:05 AM
169
+ const { container } = render(
170
+ <UserMessage content="Morning" timestamp={date} />,
171
+ );
172
+ expect(container.textContent).toContain("9:05 AM");
173
+ });
174
+
175
+ it("does not display timestamp when not provided", () => {
176
+ const { container } = render(<UserMessage content="Just text" />);
177
+ expect(container.textContent).toBe("Just text");
178
+ });
179
+ });
180
+
181
+ describe("TypingIndicator", () => {
182
+ it("renders three animated dots", () => {
183
+ const { getByLabelText } = render(<TypingIndicator />);
184
+ const indicator = getByLabelText("Typing indicator");
185
+ expect(indicator).toBeTruthy();
186
+ // Three Animated.View dots inside the container
187
+ expect(indicator.children.length).toBe(3);
188
+ });
189
+ });
@@ -0,0 +1,39 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { formatTimestamp } from "../utils";
3
+
4
+ describe("formatTimestamp", () => {
5
+ it("formats AM times correctly", () => {
6
+ const date = new Date(2025, 0, 15, 9, 5); // 9:05 AM
7
+ expect(formatTimestamp(date)).toBe("9:05 AM");
8
+ });
9
+
10
+ it("formats PM times correctly", () => {
11
+ const date = new Date(2025, 0, 15, 14, 30); // 2:30 PM
12
+ expect(formatTimestamp(date)).toBe("2:30 PM");
13
+ });
14
+
15
+ it("formats 12:00 PM (noon) correctly", () => {
16
+ const date = new Date(2025, 0, 15, 12, 0);
17
+ expect(formatTimestamp(date)).toBe("12:00 PM");
18
+ });
19
+
20
+ it("formats 12:00 AM (midnight) correctly", () => {
21
+ const date = new Date(2025, 0, 15, 0, 0);
22
+ expect(formatTimestamp(date)).toBe("12:00 AM");
23
+ });
24
+
25
+ it("pads single-digit minutes with leading zero", () => {
26
+ const date = new Date(2025, 0, 15, 8, 3);
27
+ expect(formatTimestamp(date)).toBe("8:03 AM");
28
+ });
29
+
30
+ it("formats 11:59 PM correctly", () => {
31
+ const date = new Date(2025, 0, 15, 23, 59);
32
+ expect(formatTimestamp(date)).toBe("11:59 PM");
33
+ });
34
+
35
+ it("formats 1:00 AM correctly", () => {
36
+ const date = new Date(2025, 0, 15, 1, 0);
37
+ expect(formatTimestamp(date)).toBe("1:00 AM");
38
+ });
39
+ });
@@ -0,0 +1,8 @@
1
+ export { AssistantMessage } from "./AssistantMessage";
2
+ export type { AssistantMessageProps } from "./AssistantMessage";
3
+
4
+ export { UserMessage } from "./UserMessage";
5
+ export type { UserMessageProps } from "./UserMessage";
6
+
7
+ export { TypingIndicator } from "./TypingIndicator";
8
+ export type { TypingIndicatorProps } from "./TypingIndicator";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Format a Date as a 12-hour time string (e.g. "2:05 PM").
3
+ */
4
+ export function formatTimestamp(date: Date): string {
5
+ const hours = date.getHours();
6
+ const minutes = date.getMinutes();
7
+ const ampm = hours >= 12 ? "PM" : "AM";
8
+ const displayHours = hours % 12 || 12;
9
+ const displayMinutes = minutes.toString().padStart(2, "0");
10
+ return `${displayHours}:${displayMinutes} ${ampm}`;
11
+ }
@@ -0,0 +1,150 @@
1
+ import React, {
2
+ createContext,
3
+ useCallback,
4
+ useContext,
5
+ useMemo,
6
+ useRef,
7
+ useSyncExternalStore,
8
+ } from "react";
9
+
10
+ /**
11
+ * Props passed to a render tool function.
12
+ */
13
+ export interface RenderToolProps<T = Record<string, unknown>> {
14
+ args: T;
15
+ status: "executing" | "complete";
16
+ result?: string;
17
+ }
18
+
19
+ /**
20
+ * A render function that returns a React Native element for a tool call.
21
+ * Returns `ReactElement | null` (not ReactNode) because React Native's
22
+ * FlatList cannot render strings or portals.
23
+ */
24
+ export type RenderToolFunction<T = Record<string, unknown>> = (
25
+ props: RenderToolProps<T>,
26
+ ) => React.ReactElement | null;
27
+
28
+ /**
29
+ * The registry maps tool names to their render functions.
30
+ */
31
+ export type RenderToolRegistry = Map<string, RenderToolFunction>;
32
+
33
+ /**
34
+ * Internal store that notifies subscribers when the registry changes.
35
+ * This avoids unnecessary re-renders of the entire tree when a single
36
+ * tool's render function is registered or removed.
37
+ */
38
+ interface RegistryStore {
39
+ registry: RenderToolRegistry;
40
+ version: number;
41
+ listeners: Set<() => void>;
42
+ }
43
+
44
+ function createRegistryStore(): RegistryStore {
45
+ return {
46
+ registry: new Map(),
47
+ version: 0,
48
+ listeners: new Set(),
49
+ };
50
+ }
51
+
52
+ function emitChange(store: RegistryStore) {
53
+ store.version++;
54
+ // Create a new Map so useSyncExternalStore detects the reference change
55
+ store.registry = new Map(store.registry);
56
+ for (const listener of store.listeners) {
57
+ listener();
58
+ }
59
+ }
60
+
61
+ interface RenderToolContextValue {
62
+ store: RegistryStore;
63
+ register: (name: string, render: RenderToolFunction) => () => void;
64
+ }
65
+
66
+ const RenderToolCtx = createContext<RenderToolContextValue | null>(null);
67
+
68
+ /**
69
+ * Provider that maintains the render tool registry.
70
+ * Should be nested inside CopilotKitProvider.
71
+ */
72
+ export function RenderToolProvider({
73
+ children,
74
+ }: {
75
+ children: React.ReactNode;
76
+ }) {
77
+ const storeRef = useRef<RegistryStore>(createRegistryStore());
78
+
79
+ const register = useCallback(
80
+ (name: string, render: RenderToolFunction): (() => void) => {
81
+ const store = storeRef.current;
82
+ store.registry.set(name, render);
83
+ emitChange(store);
84
+
85
+ // Return unregister function
86
+ return () => {
87
+ // Only delete if the current render function is the one we registered
88
+ if (store.registry.get(name) === render) {
89
+ store.registry.delete(name);
90
+ emitChange(store);
91
+ }
92
+ };
93
+ },
94
+ [],
95
+ );
96
+
97
+ const value = useMemo<RenderToolContextValue>(
98
+ () => ({ store: storeRef.current, register }),
99
+ [register],
100
+ );
101
+
102
+ return (
103
+ <RenderToolCtx.Provider value={value}>{children}</RenderToolCtx.Provider>
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Returns the current render tool registry (a Map of tool name to render function).
109
+ * Re-renders when the registry changes.
110
+ *
111
+ * @throws if called outside of RenderToolProvider
112
+ */
113
+ export function useRenderToolRegistry(): RenderToolRegistry {
114
+ const ctx = useContext(RenderToolCtx);
115
+ if (!ctx) {
116
+ throw new Error(
117
+ "useRenderToolRegistry must be used within a RenderToolProvider",
118
+ );
119
+ }
120
+
121
+ const { store } = ctx;
122
+
123
+ // Subscribe to registry changes via useSyncExternalStore for tear-safe reads
124
+ return useSyncExternalStore(
125
+ (onStoreChange) => {
126
+ store.listeners.add(onStoreChange);
127
+ return () => {
128
+ store.listeners.delete(onStoreChange);
129
+ };
130
+ },
131
+ () => store.registry,
132
+ () => store.registry,
133
+ );
134
+ }
135
+
136
+ /**
137
+ * Internal hook used by useRenderTool to register a render function.
138
+ * Not exported from the package — consumers use useRenderTool instead.
139
+ *
140
+ * @throws if called outside of RenderToolProvider
141
+ */
142
+ export function useRenderToolContext() {
143
+ const ctx = useContext(RenderToolCtx);
144
+ if (!ctx) {
145
+ throw new Error(
146
+ "useRenderTool must be used within a RenderToolProvider (inside CopilotKitProvider)",
147
+ );
148
+ }
149
+ return ctx;
150
+ }
@@ -0,0 +1,264 @@
1
+ import React from "react";
2
+ import { render, act } from "@testing-library/react";
3
+ import { describe, it, expect, vi, beforeEach } from "vitest";
4
+ import {
5
+ RenderToolProvider,
6
+ useRenderToolRegistry,
7
+ useRenderToolContext,
8
+ } from "../RenderToolContext";
9
+
10
+ describe("RenderToolContext", () => {
11
+ describe("RenderToolProvider", () => {
12
+ it("renders children", () => {
13
+ const { getByText } = render(
14
+ <RenderToolProvider>
15
+ <span>child content</span>
16
+ </RenderToolProvider>,
17
+ );
18
+ expect(getByText("child content")).toBeTruthy();
19
+ });
20
+
21
+ it("provides an initially empty registry", () => {
22
+ let registry: Map<string, any> | null = null;
23
+
24
+ function Reader() {
25
+ registry = useRenderToolRegistry();
26
+ return null;
27
+ }
28
+
29
+ render(
30
+ <RenderToolProvider>
31
+ <Reader />
32
+ </RenderToolProvider>,
33
+ );
34
+
35
+ expect(registry).not.toBeNull();
36
+ expect(registry!.size).toBe(0);
37
+ });
38
+ });
39
+
40
+ describe("register and unregister", () => {
41
+ it("register adds a render function to the registry", () => {
42
+ let registry: Map<string, any> | null = null;
43
+ let registerFn: ((name: string, render: any) => () => void) | null = null;
44
+
45
+ function Writer() {
46
+ const ctx = useRenderToolContext();
47
+ registerFn = ctx.register;
48
+ return null;
49
+ }
50
+
51
+ function Reader() {
52
+ registry = useRenderToolRegistry();
53
+ return null;
54
+ }
55
+
56
+ render(
57
+ <RenderToolProvider>
58
+ <Writer />
59
+ <Reader />
60
+ </RenderToolProvider>,
61
+ );
62
+
63
+ const renderFn = () => React.createElement("div");
64
+
65
+ act(() => {
66
+ registerFn!("test-tool", renderFn);
67
+ });
68
+
69
+ expect(registry!.has("test-tool")).toBe(true);
70
+ });
71
+
72
+ it("unregister removes the render function", () => {
73
+ let registry: Map<string, any> | null = null;
74
+ let registerFn: ((name: string, render: any) => () => void) | null = null;
75
+ let unregister: (() => void) | null = null;
76
+
77
+ function Writer() {
78
+ const ctx = useRenderToolContext();
79
+ registerFn = ctx.register;
80
+ return null;
81
+ }
82
+
83
+ function Reader() {
84
+ registry = useRenderToolRegistry();
85
+ return null;
86
+ }
87
+
88
+ render(
89
+ <RenderToolProvider>
90
+ <Writer />
91
+ <Reader />
92
+ </RenderToolProvider>,
93
+ );
94
+
95
+ const renderFn = () => React.createElement("div");
96
+
97
+ act(() => {
98
+ unregister = registerFn!("removal-tool", renderFn);
99
+ });
100
+
101
+ expect(registry!.has("removal-tool")).toBe(true);
102
+
103
+ act(() => {
104
+ unregister!();
105
+ });
106
+
107
+ expect(registry!.has("removal-tool")).toBe(false);
108
+ });
109
+
110
+ it("unregister is safe to call if tool was already replaced", () => {
111
+ let registerFn: ((name: string, render: any) => () => void) | null = null;
112
+ let registry: Map<string, any> | null = null;
113
+
114
+ function Writer() {
115
+ const ctx = useRenderToolContext();
116
+ registerFn = ctx.register;
117
+ return null;
118
+ }
119
+
120
+ function Reader() {
121
+ registry = useRenderToolRegistry();
122
+ return null;
123
+ }
124
+
125
+ render(
126
+ <RenderToolProvider>
127
+ <Writer />
128
+ <Reader />
129
+ </RenderToolProvider>,
130
+ );
131
+
132
+ const render1 = () => React.createElement("div", null, "v1");
133
+ const render2 = () => React.createElement("div", null, "v2");
134
+
135
+ let unregister1: () => void;
136
+
137
+ act(() => {
138
+ unregister1 = registerFn!("shared-tool", render1);
139
+ });
140
+
141
+ // Re-register with a different render function (simulates a new component mounting)
142
+ act(() => {
143
+ registerFn!("shared-tool", render2);
144
+ });
145
+
146
+ // Calling unregister1 should NOT remove the tool because the current
147
+ // render function is render2, not render1
148
+ act(() => {
149
+ unregister1!();
150
+ });
151
+
152
+ expect(registry!.has("shared-tool")).toBe(true);
153
+ });
154
+ });
155
+
156
+ describe("useSyncExternalStore integration", () => {
157
+ it("returns updated registry after registration", () => {
158
+ let registry: Map<string, any> | null = null;
159
+ let registerFn: ((name: string, render: any) => () => void) | null = null;
160
+
161
+ function Writer() {
162
+ const ctx = useRenderToolContext();
163
+ registerFn = ctx.register;
164
+ return null;
165
+ }
166
+
167
+ function Reader() {
168
+ registry = useRenderToolRegistry();
169
+ return null;
170
+ }
171
+
172
+ render(
173
+ <RenderToolProvider>
174
+ <Writer />
175
+ <Reader />
176
+ </RenderToolProvider>,
177
+ );
178
+
179
+ const sizeBefore = registry!.size;
180
+
181
+ act(() => {
182
+ registerFn!("tool-a", () => React.createElement("div"));
183
+ });
184
+
185
+ // After registration, the registry should contain the new tool
186
+ expect(registry!.has("tool-a")).toBe(true);
187
+ expect(registry!.size).toBe(sizeBefore + 1);
188
+ });
189
+
190
+ it("notifies multiple subscribers when registry changes", () => {
191
+ let registry1: Map<string, any> | null = null;
192
+ let registry2: Map<string, any> | null = null;
193
+ let registerFn: ((name: string, render: any) => () => void) | null = null;
194
+
195
+ function Writer() {
196
+ const ctx = useRenderToolContext();
197
+ registerFn = ctx.register;
198
+ return null;
199
+ }
200
+
201
+ function Reader1() {
202
+ registry1 = useRenderToolRegistry();
203
+ return null;
204
+ }
205
+
206
+ function Reader2() {
207
+ registry2 = useRenderToolRegistry();
208
+ return null;
209
+ }
210
+
211
+ render(
212
+ <RenderToolProvider>
213
+ <Writer />
214
+ <Reader1 />
215
+ <Reader2 />
216
+ </RenderToolProvider>,
217
+ );
218
+
219
+ act(() => {
220
+ registerFn!("multi-sub-tool", () => React.createElement("div"));
221
+ });
222
+
223
+ // Both readers should see the same registry
224
+ expect(registry1!.has("multi-sub-tool")).toBe(true);
225
+ expect(registry2!.has("multi-sub-tool")).toBe(true);
226
+ // They should be the exact same reference
227
+ expect(registry1).toBe(registry2);
228
+ });
229
+ });
230
+
231
+ describe("error handling", () => {
232
+ it("useRenderToolContext throws outside provider", () => {
233
+ function TestComponent() {
234
+ useRenderToolContext();
235
+ return null;
236
+ }
237
+
238
+ const spy = vi.spyOn(console, "error").mockImplementation(() => {});
239
+
240
+ expect(() => {
241
+ render(<TestComponent />);
242
+ }).toThrow("useRenderTool must be used within a RenderToolProvider");
243
+
244
+ spy.mockRestore();
245
+ });
246
+
247
+ it("useRenderToolRegistry throws outside provider", () => {
248
+ function TestComponent() {
249
+ useRenderToolRegistry();
250
+ return null;
251
+ }
252
+
253
+ const spy = vi.spyOn(console, "error").mockImplementation(() => {});
254
+
255
+ expect(() => {
256
+ render(<TestComponent />);
257
+ }).toThrow(
258
+ "useRenderToolRegistry must be used within a RenderToolProvider",
259
+ );
260
+
261
+ spy.mockRestore();
262
+ });
263
+ });
264
+ });