11import Hls from '../../src/hls' ;
22import { hlsDefaultConfig } from '../../src/config' ;
33import { Events } from '../../src/events' ;
4+ import { ErrorTypes , ErrorDetails } from '../../src/errors' ;
45
56import chai from 'chai' ;
67import sinonChai from 'sinon-chai' ;
8+ import sinon from 'sinon' ;
79
810chai . use ( sinonChai ) ;
911const expect = chai . expect ;
@@ -51,7 +53,8 @@ describe('Hls', function () {
5153 ) ;
5254 } ) ;
5355 }
54- it ( 'should add and remove refrences to the "media" element immediately' , function ( ) {
56+
57+ it ( 'should add and remove references to the "media" element immediately' , function ( ) {
5558 const hls = new Hls ( { capLevelOnFPSDrop : true } ) ;
5659 expect ( hls . media ) . to . equal ( null ) ;
5760 const media = document . createElement ( 'video' ) ;
@@ -62,7 +65,7 @@ describe('Hls', function () {
6265 hls . destroy ( ) ;
6366 } ) ;
6467
65- it ( 'should add and remove refrences to the "media" element after attached' , function ( ) {
68+ it ( 'should add and remove references to the "media" element after attached' , function ( ) {
6669 const hls = new Hls ( {
6770 capLevelOnFPSDrop : true ,
6871 emeEnabled : true ,
@@ -77,14 +80,45 @@ describe('Hls', function () {
7780 detachTest ( hls , media , 12 ) ;
7881 hls . destroy ( ) ;
7982 } ) ;
83+
84+ it ( 'should trigger an error event when attachMedia is called with null' , function ( ) {
85+ const hls = new Hls ( ) ;
86+ const triggerSpy = sinon . spy ( hls , 'trigger' ) ;
87+
88+ hls . on ( Events . ERROR , function ( _event , _data ) { } ) ;
89+ ( hls as any ) . attachMedia ( null ) ;
90+
91+ const expectedEvent = {
92+ type : ErrorTypes . OTHER_ERROR ,
93+ details : ErrorDetails . ATTACH_MEDIA_ERROR ,
94+ fatal : true ,
95+ error : sinon . match
96+ . instanceOf ( Error )
97+ . and (
98+ sinon . match . has (
99+ 'message' ,
100+ 'attachMedia failed: media argument is null' ,
101+ ) ,
102+ ) ,
103+ } ;
104+
105+ expect ( triggerSpy ) . to . be . calledWith (
106+ Events . ERROR ,
107+ sinon . match ( expectedEvent ) ,
108+ ) ;
109+
110+ triggerSpy . restore ( ) ;
111+ hls . destroy ( ) ;
112+ } ) ;
80113 } ) ;
81114
82115 describe ( 'loadSource and url' , function ( ) {
83- it ( 'url should initally be null' , function ( ) {
116+ it ( 'url should initially be null' , function ( ) {
84117 const hls = new Hls ( ) ;
85118 expect ( hls . url ) . to . equal ( null ) ;
86119 hls . destroy ( ) ;
87120 } ) ;
121+
88122 it ( 'should return given url after load' , function ( ) {
89123 const hls = new Hls ( ) ;
90124 hls . loadSource (
@@ -95,6 +129,7 @@ describe('Hls', function () {
95129 ) ;
96130 hls . destroy ( ) ;
97131 } ) ;
132+
98133 it ( 'should make relative url absolute' , function ( ) {
99134 const hls = new Hls ( ) ;
100135 hls . loadSource ( '/streams/x36xhzz/x36xhzz.m3u8' ) ;
0 commit comments