Skip to content

🎥 Make videos programmatically with React

add more test cases

Shankhadeep Dey6a6458979a3b
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 337a32c9f7..f624da631f 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -103,39 +103,45 @@ export const PlayerFn = <T,>(
);
}
- if (typeof controls !== 'boolean') {
+ if (typeof controls !== 'boolean' && typeof controls !== 'undefined') {
throw new TypeError(
- `'loop' must be a boolean but got '${typeof controls}' instead`
+ `'controls' must be a boolean or undefined but got '${typeof controls}' instead`
);
}
- if (typeof autoPlay !== 'boolean') {
+ if (typeof autoPlay !== 'boolean' && typeof autoPlay !== 'undefined') {
throw new TypeError(
- `'autoPlay' must be a boolean but got '${typeof autoPlay}' instead`
+ `'autoPlay' must be a boolean or undefined but got '${typeof autoPlay}' instead`
);
}
- if (typeof loop !== 'boolean') {
+ if (typeof loop !== 'boolean' && typeof loop !== 'undefined') {
throw new TypeError(
- `'loop' must be a boolean but got '${typeof loop}' instead`
+ `'loop' must be a boolean or undefined but got '${typeof loop}' instead`
);
}
- if (typeof showVolumeControls !== 'boolean') {
+ if (
+ typeof showVolumeControls !== 'boolean' &&
+ typeof showVolumeControls !== 'undefined'
+ ) {
throw new TypeError(
- `'showVolumeControls' must be a boolean but got '${typeof showVolumeControls}' instead`
+ `'showVolumeControls' must be a boolean or undefined but got '${typeof showVolumeControls}' instead`
);
}
- if (typeof allowFullscreen !== 'boolean') {
+ if (
+ typeof allowFullscreen !== 'boolean' &&
+ typeof allowFullscreen !== 'undefined'
+ ) {
throw new TypeError(
- `'allowFullscreen' must be a boolean but got '${typeof allowFullscreen}' instead`
+ `'allowFullscreen' must be a boolean or undefined but got '${typeof allowFullscreen}' instead`
);
}
- if (typeof clickToPlay !== 'boolean') {
+ if (typeof clickToPlay !== 'boolean' && typeof clickToPlay !== 'undefined') {
throw new TypeError(
- `'clickToPlay' must be a boolean but got '${typeof clickToPlay}' instead`
+ `'clickToPlay' must be a boolean or undefined but got '${typeof clickToPlay}' instead`
);
}
diff --git a/packages/player/src/test/validate-prop.test.tsx b/packages/player/src/test/validate-prop.test.tsx
index c029d78ba2..31956e5ce9 100644
--- a/packages/player/src/test/validate-prop.test.tsx
+++ b/packages/player/src/test/validate-prop.test.tsx
@@ -1,7 +1,7 @@
import {Player} from '../index';
import {HelloWorld, render} from './test-utils';
-test('no durationInFrames should give errors', () => {
+test('no compositionWidth should give errors', () => {
try {
render(
<Player
@@ -21,3 +21,113 @@ test('no durationInFrames should give errors', () => {
);
}
});
+
+test('no compositionHeight should give errors', () => {
+ try {
+ render(
+ <Player
+ compositionWidth={400}
+ // @ts-expect-error
+ compositionHeight={undefined}
+ fps={30}
+ durationInFrames={500}
+ component={HelloWorld}
+ controls
+ showVolumeControls
+ />
+ );
+ } catch (e) {
+ expect(e.message).toMatch(
+ /'compositionHeight' must be a number but got 'undefined' instead/
+ );
+ }
+});
+
+test('No fps should give errors', () => {
+ try {
+ render(
+ <Player
+ compositionWidth={500}
+ compositionHeight={400}
+ // @ts-expect-error
+ fps={null}
+ durationInFrames={500}
+ component={HelloWorld}
+ controls
+ showVolumeControls
+ />
+ );
+ } catch (e) {
+ expect(e.message).toMatch(
+ /'fps' must be a number but got 'object' instead/
+ );
+ }
+
+ try {
+ render(
+ <Player
+ compositionWidth={500}
+ compositionHeight={400}
+ // @ts-expect-error
+ fps={undefined}
+ durationInFrames={500}
+ component={HelloWorld}
+ controls
+ showVolumeControls
+ />
+ );
+ } catch (e) {
+ expect(e.message).toMatch(
+ /'fps' must be a number but got 'undefined' instead/
+ );
+ }
+});
+
+test('No durationInFrames should give errors', () => {
+ try {
+ render(
+ <Player
+ compositionWidth={500}
+ compositionHeight={400}
+ fps={30}
+ // @ts-expect-error
+ durationInFrames={undefined}
+ component={HelloWorld}
+ controls
+ showVolumeControls
+ />
+ );
+ } catch (e) {
+ expect(e.message).toMatch(
+ /'durationInFrames' must be a number but got 'undefined' instead/
+ );
+ }
+});
+
+test.each([
+ ['controls'],
+ ['loop'],
+ ['autoPlay'],
+ ['showVolumeControls'],
+ ['allowFullscreen'],
+ ['clickToPlay'],
+])('No durationInFrames should give errors %s', (a: string) => {
+ const props: {[name: string]: string} = {};
+ props[a] = 'hey';
+ try {
+ render(
+ <Player
+ compositionWidth={500}
+ compositionHeight={400}
+ fps={30}
+ durationInFrames={100}
+ component={HelloWorld}
+ {...props}
+ />
+ );
+ } catch (e) {
+ expect(e.message).toMatch(
+ `'${a}' must be a boolean or undefined but got 'string' instead`
+ );
+ }
+});