🎥 Make videos programmatically with React
add validation to sequence - from and durationInFrames must be integer
Jonny Burgerba46aca246a6
diff --git a/packages/core/src/sequencing/index.tsx b/packages/core/src/sequencing/index.tsxindex bb0f0fd8b6..5f2a339059 100644--- a/packages/core/src/sequencing/index.tsx+++ b/packages/core/src/sequencing/index.tsx@@ -62,11 +62,22 @@ export const Sequence: React.FC<{`durationInFrames must be positive, but got ${durationInFrames}`);}+ // Infinity is non-integer but allowed!+ if (durationInFrames % 1 !== 0 && Number.isFinite(durationInFrames)) {+ throw new TypeError(+ `The "durationInFrames" of a sequence must be an integer, but got ${durationInFrames}.`+ );+ }if (typeof from !== 'number') {throw new TypeError(`You passed to the "from" props of your <Sequence> an argument of type ${typeof from}, but it must be a number.`);}+ if (from % 1 !== 0) {+ throw new TypeError(+ `The "from" prop of a sequence must be an integer, but got ${from}.`+ );+ }const absoluteFrame = useAbsoluteCurrentFrame();const unsafeVideoConfig = useUnsafeVideoConfig();diff --git a/packages/core/src/test/sequence-validation.test.tsx b/packages/core/src/test/sequence-validation.test.tsxindex 3e18c6729a..5ccb2e21c6 100644--- a/packages/core/src/test/sequence-validation.test.tsx+++ b/packages/core/src/test/sequence-validation.test.tsx@@ -19,6 +19,41 @@ test('It should throw if Sequence has missing duration', () => {);});+test('It should throw if Sequence has non-integer durationInFrames', () => {+ expectToThrow(+ () =>+ render(+ <Sequence from={0} durationInFrames={1.1}>+ hi+ </Sequence>+ ),+ /The "durationInFrames" of a sequence must be an integer, but got 1.1./+ );+});+test('It should throw if Sequence has non-integer from', () => {+ expectToThrow(+ () =>+ render(+ <Sequence from={0.1} durationInFrames={1}>+ hi+ </Sequence>+ ),+ /The "from" prop of a sequence must be an integer, but got 0.1./+ );+});++test('It should throw if Sequence has missing duration', () => {+ expectToThrow(+ () =>+ render(+ <Sequence from={0} durationInFrames={1.1}>+ hi+ </Sequence>+ ),+ /The "durationInFrames" of a sequence must be an integer, but got 1.1./+ );+});+test('It should throw if Sequence has negative duration', () => {expectToThrow(// @ts-expect-error