@@ -128,6 +128,17 @@ describe('mount', () => {
128128 } )
129129
130130 describe ( 'for svg' , ( ) => {
131+ it ( 'renders foreignObject and sets dimensions' , ( ) => {
132+ render (
133+ < svg >
134+ < foreignObject x = "50" y = "100" width = "150" height = "200" />
135+ </ svg > ,
136+ )
137+ expect ( root ?. innerHTML ?? '' ) . toBe (
138+ '<svg><foreignObject height="200" x="50" width="150" y="100"></foreignObject></svg>' ,
139+ )
140+ } )
141+
131142 it ( 'sets the d' , ( ) => {
132143 render ( < fast-path d = "M0,0 L0,10 Z" /> )
133144 expect ( root ?. innerHTML ?? '' ) . toBe ( '<path d="M0,0 L0,10 Z"></path>' )
@@ -517,6 +528,22 @@ describe('mount', () => {
517528 } )
518529
519530 describe ( 'for svg' , ( ) => {
531+ it ( 'renders foreignObject and sets dimensions' , ( ) => {
532+ const xFacet = createFacet ( { initialValue : '50' } )
533+ const yFacet = createFacet ( { initialValue : '100' } )
534+ const widthFacet = createFacet ( { initialValue : '150' } )
535+ const heightFacet = createFacet ( { initialValue : '200' } )
536+
537+ render (
538+ < svg >
539+ < fast-foreignObject x = { xFacet } y = { yFacet } width = { widthFacet } height = { heightFacet } />
540+ </ svg > ,
541+ )
542+ expect ( root ?. innerHTML ?? '' ) . toBe (
543+ '<svg><foreignObject height="200" x="50" width="150" y="100"></foreignObject></svg>' ,
544+ )
545+ } )
546+
520547 it ( 'sets the d' , ( ) => {
521548 const dFacet = createFacet ( { initialValue : 'M0,0 L0,10 Z' } )
522549
@@ -1213,6 +1240,48 @@ describe('update', () => {
12131240 } )
12141241
12151242 describe ( 'for svg' , ( ) => {
1243+ it ( 'updates foreignObject dimensions' , ( ) => {
1244+ const MockComponent = ( ) => {
1245+ const [ xFacet , setXFacet ] = useState < string | undefined > ( '50' )
1246+ const [ yFacet , setYFacet ] = useState < string | undefined > ( '100' )
1247+ const [ widthFacet , setWidthFacet ] = useState < string | undefined > ( '150' )
1248+ const [ heightFacet , setHeightFacet ] = useState < string | undefined > ( '200' )
1249+
1250+ useEffect ( ( ) => {
1251+ setTimeout ( ( ) => setXFacet ( '350' ) , 1 )
1252+ setTimeout ( ( ) => setYFacet ( '400' ) , 2 )
1253+ setTimeout ( ( ) => setWidthFacet ( '450' ) , 3 )
1254+ setTimeout ( ( ) => setHeightFacet ( '500' ) , 4 )
1255+ } , [ ] )
1256+ return (
1257+ < svg >
1258+ < fast-foreignObject x = { xFacet } y = { yFacet } width = { widthFacet } height = { heightFacet } />
1259+ </ svg >
1260+ )
1261+ }
1262+
1263+ render ( < MockComponent /> )
1264+ expect ( root ?. innerHTML ?? '' ) . toBe (
1265+ '<svg><foreignObject height="200" x="50" width="150" y="100"></foreignObject></svg>' ,
1266+ )
1267+ jest . advanceTimersByTime ( 1 )
1268+ expect ( root ?. innerHTML ?? '' ) . toBe (
1269+ '<svg><foreignObject height="200" x="350" width="150" y="100"></foreignObject></svg>' ,
1270+ )
1271+ jest . advanceTimersByTime ( 1 )
1272+ expect ( root ?. innerHTML ?? '' ) . toBe (
1273+ '<svg><foreignObject height="200" x="350" width="150" y="400"></foreignObject></svg>' ,
1274+ )
1275+ jest . advanceTimersByTime ( 1 )
1276+ expect ( root ?. innerHTML ?? '' ) . toBe (
1277+ '<svg><foreignObject height="200" x="350" width="450" y="400"></foreignObject></svg>' ,
1278+ )
1279+ jest . advanceTimersByTime ( 1 )
1280+ expect ( root ?. innerHTML ?? '' ) . toBe (
1281+ '<svg><foreignObject height="500" x="350" width="450" y="400"></foreignObject></svg>' ,
1282+ )
1283+ } )
1284+
12161285 it ( 'updates d' , ( ) => {
12171286 const MockComponent = ( ) => {
12181287 const [ d , setD ] = useState < string | undefined > ( 'M0,0 L0,10 Z' )
0 commit comments