@@ -2,6 +2,7 @@ import React from 'react';
2
2
import { renderHook } from '@testing-library/react' ;
3
3
4
4
import { useMediaStreamInVideo } from '../useMediaStreamInVideo' ;
5
+ import { STATIC_VIDEO_CONSTRAINTS } from '../../utils/helpers' ;
5
6
6
7
describe ( 'useMediaStreamInVideo' , ( ) => {
7
8
it ( 'should return videoRef, videoHeight, videoWidth' , ( ) => {
@@ -32,4 +33,47 @@ describe('useMediaStreamInVideo', () => {
32
33
expect ( stream . removeTrack ) . toHaveBeenCalledWith ( track ) ;
33
34
expect ( track . stop ) . toHaveBeenCalled ( ) ;
34
35
} ) ;
36
+
37
+ it ( 'should handle stream with no tracks' , ( ) => {
38
+ const stream = {
39
+ getTracks : ( ) => [ ] ,
40
+ removeTrack : jest . fn ( ) ,
41
+ } as unknown as MediaStream ;
42
+
43
+ const { result, unmount } = renderHook ( ( ) => useMediaStreamInVideo ( stream ) ) ;
44
+
45
+ const height = ( STATIC_VIDEO_CONSTRAINTS . height as ConstrainULongRange )
46
+ . ideal ;
47
+ const width = ( STATIC_VIDEO_CONSTRAINTS . width as ConstrainULongRange ) . ideal ;
48
+
49
+ expect ( result . current . videoHeight ) . toBe ( height ) ;
50
+ expect ( result . current . videoWidth ) . toBe ( width ) ;
51
+
52
+ unmount ( ) ;
53
+ } ) ;
54
+
55
+ it ( 'should handle stream track with no settings' , ( ) => {
56
+ const track = {
57
+ getSettings : ( ) => undefined ,
58
+ stop : jest . fn ( ) ,
59
+ } as unknown as MediaStreamTrack ;
60
+
61
+ const stream = {
62
+ getTracks : ( ) => [ track ] ,
63
+ removeTrack : jest . fn ( ) ,
64
+ } as unknown as MediaStream ;
65
+
66
+ const { result, unmount } = renderHook ( ( ) => useMediaStreamInVideo ( stream ) ) ;
67
+
68
+ const height = ( STATIC_VIDEO_CONSTRAINTS . height as ConstrainULongRange )
69
+ . ideal ;
70
+ const width = ( STATIC_VIDEO_CONSTRAINTS . width as ConstrainULongRange ) . ideal ;
71
+
72
+ expect ( result . current . videoHeight ) . toBe ( height ) ;
73
+ expect ( result . current . videoWidth ) . toBe ( width ) ;
74
+
75
+ unmount ( ) ;
76
+ expect ( stream . removeTrack ) . toHaveBeenCalledWith ( track ) ;
77
+ expect ( track . stop ) . toHaveBeenCalled ( ) ;
78
+ } ) ;
35
79
} ) ;
0 commit comments