@@ -1796,11 +1796,14 @@ describe("keyframe mutations", () => {
17961796 [ "recast" , syncPositionHoldsBeforeKeyframes ] ,
17971797 [ "acorn" , syncPositionHoldsBeforeKeyframesAcorn ] ,
17981798 ] ) ( "%s: holds a lone size keyframe from t=0, wherever its tween starts" , ( _ , sync ) => {
1799+ const timeline = `const tl = gsap.timeline({ paused: true });\n` ;
17991800 for ( const start of [ 0 , 1.5 ] ) {
18001801 const script =
18011802 `const tl = gsap.timeline({ paused: true });\n` +
18021803 `tl.to("#s", { keyframes: { "0%": { width: 440, height: 294 } }, duration: 3 }, ${ start } );` ;
1803- const hold = parseGsapScript ( sync ( script ) ) . animations . find ( ( a ) => a . method === "set" ) ;
1804+ const hold = parseGsapScript ( sync ( script , timeline ) ) . animations . find (
1805+ ( a ) => a . method === "set" ,
1806+ ) ;
18041807 expect ( hold ! . position ) . toBe ( 0 ) ;
18051808 expect ( hold ! . properties ) . toEqual ( { width : 440 , height : 294 , data : "hf-hold" } ) ;
18061809 }
@@ -1814,11 +1817,33 @@ describe("keyframe mutations", () => {
18141817 ( _ , sync ) => {
18151818 const timeline = `const tl = gsap.timeline({ paused: true });\n` ;
18161819 const keys = `"0%": { width: 100 }, "100%": { width: 400 }` ;
1817- expect (
1818- sync ( `${ timeline } tl.to("#s", { keyframes: { ${ keys } }, duration: 1 }, 2);` ) ,
1819- ) . not . toContain ( "hf-hold" ) ;
1820+ const twoKeys = `${ timeline } tl.to("#s", { keyframes: { ${ keys } }, duration: 1 }, 2);` ;
1821+ expect ( sync ( twoKeys , timeline ) ) . not . toContain ( "hf-hold" ) ;
18201822 const atLabel = `${ timeline } tl.to("#s", { width: 300, duration: 1 }, 1);\ntl.to("#s", { keyframes: { "0%": { width: 500 } }, duration: 1 }, "later");` ;
1821- expect ( sync ( atLabel ) ) . not . toContain ( "hf-hold" ) ;
1823+ expect ( sync ( atLabel , timeline ) ) . not . toContain ( "hf-hold" ) ;
1824+ } ,
1825+ ) ;
1826+
1827+ it . each ( [
1828+ [ "recast" , syncPositionHoldsBeforeKeyframes ] ,
1829+ [ "acorn" , syncPositionHoldsBeforeKeyframesAcorn ] ,
1830+ ] ) (
1831+ "%s: keeps a size hold when its lone key gains a second, and adds none to a tween left alone" ,
1832+ ( _ , sync ) => {
1833+ const timeline = `const tl = gsap.timeline({ paused: true });\n` ;
1834+ const held = `tl.set("#s", { width: 440, height: 294, data: "hf-hold" }, 0);\n` ;
1835+ const lone = `tl.to("#s", { keyframes: { "0%": { width: 440, height: 294 } }, duration: 2 }, 3);` ;
1836+ const two = `tl.to("#s", { keyframes: { "0%": { width: 380, height: 250 }, "100%": { width: 440, height: 294 } }, duration: 1 }, 2);` ;
1837+ const hold = parseGsapScript (
1838+ sync ( timeline + held + two , timeline + held + lone ) ,
1839+ ) . animations . find ( ( a ) => a . method === "set" ) ;
1840+ expect ( hold ?. properties ) . toEqual ( { width : 380 , height : 250 , data : "hf-hold" } ) ;
1841+
1842+ const untouched = `${ timeline } tl.to("#u", { keyframes: { "0%": { width: 500 } }, duration: 1 }, 1);\n` ;
1843+ const edited = `${ untouched } tl.to("#v", { opacity: 1, duration: 1 }, 0);` ;
1844+ const deleted = `${ timeline } ${ held } tl.to("#s", { keyframes: { "0%": { width: 600 }, "100%": { width: 700 } }, duration: 1 }, 6);` ;
1845+ expect ( sync ( deleted , deleted + `\n${ lone } ` ) ) . not . toContain ( "hf-hold" ) ;
1846+ expect ( sync ( edited , untouched ) ) . not . toContain ( "hf-hold" ) ;
18221847 } ,
18231848 ) ;
18241849
0 commit comments