Skip to content

🎥 Make videos programmatically with React

test Video.tsx renders correctly with props

Tobias Bonerf4784d4989bb
diff --git a/packages/core/src/test/video.test.tsx b/packages/core/src/test/video.test.tsx
index 662d774ee8..bac34f87a0 100644
--- a/packages/core/src/test/video.test.tsx
+++ b/packages/core/src/test/video.test.tsx
@@ -1,59 +1,81 @@
import {render} from '@testing-library/react';
-import React from 'react';
+import React, {useContext} from 'react';
+import {Internals} from '../internals';
import {Video} from '../video';
import {expectToThrow} from './expect-to-throw';
-test('It should throw if startFrom prop is negative', () => {
- expectToThrow(
- () => render(<Video startFrom={-40} />),
- /startFrom must be greater than equal to 0 instead got -40./
+const Wrapper: React.FC = ({children}) => {
+ const compositions = useContext(Internals.CompositionManager);
+ return (
+ <Internals.RemotionRoot>
+ <Internals.CompositionManager.Provider
+ value={{
+ ...compositions,
+ compositions: [
+ {
+ height: 1080,
+ width: 1080,
+ fps: 30,
+ durationInFrames: 30,
+ id: 'markup',
+ nonce: 0,
+ component: React.lazy(() =>
+ Promise.resolve({
+ default: (() => null) as React.ComponentType<unknown>,
+ })
+ ),
+ },
+ ],
+ currentComposition: 'markup',
+ }}
+ >
+ {children}
+ </Internals.CompositionManager.Provider>
+ </Internals.RemotionRoot>
);
-});
-
-test('It should throw if endAt prop is negative', () => {
- expectToThrow(
- () => render(<Video endAt={-40} />),
- /endAt must be a positive number, instead got -40./
- );
-});
-
-test('It should throw if endAt is less than startFrom', () => {
- expectToThrow(
- () => render(<Video startFrom={10} endAt={1} />),
- /endAt prop must be greater than startFrom prop/
- );
-});
-
-test('It should throw if endAt is not a number', () => {
- expectToThrow(
- //@ts-expect-error
- () => render(<Video endAt={'hey'} />),
- /type of endAt prop must be a number, instead got type string./
- );
-});
+};
-test('It should throw if startFrom is not a number', () => {
- expectToThrow(
- //@ts-expect-error
- () => render(<Video startFrom={'hey'} />),
- /type of startFrom prop must be a number, instead got type string./
- );
-});
-
-test('It should throw if endAt is NaN', () => {
- expectToThrow(
- () => render(<Video endAt={NaN} />),
- /endAt prop can not be NaN./
- );
-});
-
-test('It should throw if startFrom is NaN or Infinity', () => {
- expectToThrow(
- () => render(<Video startFrom={NaN} />),
- /startFrom prop can not be NaN or Infinity./
- );
- expectToThrow(
- () => render(<Video startFrom={Infinity} />),
- /startFrom prop can not be NaN or Infinity./
- );
+describe('Render correctly with props', () => {
+ test('It should render Video without startFrom / endAt props', () => {
+ expect(() =>
+ render(
+ <Wrapper>
+ <Video src="test" />
+ </Wrapper>
+ )
+ ).not.toThrow();
+ });
+ test('It should render Video with startFrom props', () => {
+ expect(() =>
+ render(
+ <Wrapper>
+ <Video src="test" startFrom={10} />
+ </Wrapper>
+ )
+ ).not.toThrow();
+ });
+ test('It should render Video with endAt props', () => {
+ expect(() =>
+ render(
+ <Wrapper>
+ <Video src="test" endAt={10} />
+ </Wrapper>
+ )
+ ).not.toThrow();
+ });
+ test('It should render Video with startFrom and endAt props', () => {
+ expect(() =>
+ render(
+ <Wrapper>
+ <Video src="test" startFrom={10} endAt={15} />
+ </Wrapper>
+ )
+ ).not.toThrow();
+ });
+ test('It should throw if videoConfig/Wrapper is missing', () => {
+ expectToThrow(
+ () => render(<Video startFrom={10} endAt={15} />),
+ /No video config found/
+ );
+ });
});