11import { render , waitFor } from "@testing-library/react" ;
22import React from "react" ;
33import { describe , expect , it } from "vitest" ;
4+ import { StreamdownContext , type StreamdownContextType } from "../index" ;
45import { components as importedComponents } from "../lib/components" ;
56import type { Options } from "../lib/markdown" ;
67
8+ const createContextValue = (
9+ linkSafety ?: StreamdownContextType [ "linkSafety" ]
10+ ) : StreamdownContextType => ( {
11+ shikiTheme : [ "github-light" , "github-dark" ] ,
12+ controls : true ,
13+ isAnimating : false ,
14+ mode : "streaming" ,
15+ mermaid : undefined ,
16+ linkSafety,
17+ } ) ;
18+
719// Type assertion: we know all components are defined in our implementation
820type RequiredComponents = Required < NonNullable < Options [ "components" ] > > ;
921const components = importedComponents as RequiredComponents ;
@@ -151,9 +163,11 @@ describe("Markdown Components", () => {
151163 throw new Error ( "A component not found" ) ;
152164 }
153165 const { container } = render (
154- < A href = "https://example.com" node = { null as any } >
155- Link text
156- </ A >
166+ < StreamdownContext . Provider value = { createContextValue ( ) } >
167+ < A href = "https://example.com" node = { null as any } >
168+ Link text
169+ </ A >
170+ </ StreamdownContext . Provider >
157171 ) ;
158172 const link = container . querySelector ( "a" ) ;
159173 expect ( link ) . toBeTruthy ( ) ;
@@ -171,9 +185,11 @@ describe("Markdown Components", () => {
171185 throw new Error ( "A component not found" ) ;
172186 }
173187 const { container } = render (
174- < A href = "streamdown:incomplete-link" node = { null as any } >
175- Incomplete link text
176- </ A >
188+ < StreamdownContext . Provider value = { createContextValue ( ) } >
189+ < A href = "streamdown:incomplete-link" node = { null as any } >
190+ Incomplete link text
191+ </ A >
192+ </ StreamdownContext . Provider >
177193 ) ;
178194 // Should render a normal anchor with data-incomplete attribute
179195 const link = container . querySelector ( 'a[data-streamdown="link"]' ) ;
0 commit comments