Skip to content

🎥 Make videos programmatically with React

improve test code quality

Tobias Boner07d7ae772ff6
diff --git a/packages/core/src/test/media-validation.test.tsx b/packages/core/src/test/media-validation.test.tsx
index c508801dcd..3bd2670d0b 100644
--- a/packages/core/src/test/media-validation.test.tsx
+++ b/packages/core/src/test/media-validation.test.tsx
@@ -1,48 +1,42 @@
import {validateMediaProps} from '../validate-media-props';
import {expectToThrow} from './expect-to-throw';
-test('It should not allow a video to have a negative volume', () => {
- expectToThrow(
- () => validateMediaProps({volume: -1}, 'Video'),
- /You have passed a volume below 0 to your <Video \/> component./
- );
-});
-
-test('It should not allow an audio element to have a negative volume', () => {
- expectToThrow(
- () => validateMediaProps({volume: -1}, 'Audio'),
- /You have passed a volume below 0 to your <Audio \/> component./
- );
-});
-
-test('It should not allow an audio element to have a wrong type', () => {
- expectToThrow(
- // @ts-expect-error
- () => validateMediaProps({volume: 'wrong'}, 'Audio'),
- /You have passed a volume of type string to your <Audio \/> component./
- );
+describe('ValidateMediaProps should throw with invalid volume inputs', () => {
+ const testComponents: string[] = ['Audio', 'Video'];
+ testComponents.forEach((component) => {
+ test(`It should not allow an ${component} element to have a negative volume `, () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => validateMediaProps({volume: -1}, component),
+ new RegExp(
+ `You have passed a volume below 0 to your <${component} /> component. Volume must be between 0 and 1`
+ )
+ );
+ });
+ test(`It should not allow an ${component} element to have an invalid type`, () => {
+ expectToThrow(
+ // @ts-expect-error
+ () => validateMediaProps({volume: 'invalidType'}, component),
+ new RegExp(
+ `You have passed a volume of type string to your <${component} /> component.`
+ )
+ );
+ });
+ });
});
-test('It should not allow a video element to have a wrong type', () => {
- expectToThrow(
- // @ts-expect-error
- () => validateMediaProps({volume: 'wrong'}, 'Video'),
- /You have passed a volume of type string to your <Video \/> component/
+describe('ValidateMediaProps should not throw with valid volume inputs', () => {
+ const validInputs: (number | Function | undefined)[] = [
+ 0,
+ 1,
+ undefined,
+ () => 1,
+ (x: number) => x,
+ ];
+ validInputs.forEach((vol) =>
+ test(`valid volume ${vol} shold not throw`, () => {
+ // @ts-expect-error
+ expect(() => validateMediaProps({volume: vol}, 'Video')).not.toThrow();
+ })
);
});
-
-test('It should allow a valid volume', () => {
- expect(() => validateMediaProps({volume: 0}, 'Video')).not.toThrow();
-});
-test('It should allow a valid volume', () => {
- expect(() => validateMediaProps({volume: 1}, 'Video')).not.toThrow();
-});
-test('It should allow a valid volume', () => {
- expect(() => validateMediaProps({volume: undefined}, 'Video')).not.toThrow();
-});
-test('It should allow a valid volume', () => {
- expect(() => validateMediaProps({volume: () => 1}, 'Video')).not.toThrow();
-});
-test('It should allow a valid volume', () => {
- expect(() => validateMediaProps({volume: () => -1}, 'Video')).not.toThrow();
-});