From fb8627ea8f06e0a71fa093298cc6bc85254cca5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo?= Date: Fri, 29 Jan 2021 19:19:18 -0300 Subject: [PATCH] test: cover _ready method with tests --- src/hls.test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/hls.test.js b/src/hls.test.js index 427a78b..aa51900 100644 --- a/src/hls.test.js +++ b/src/hls.test.js @@ -173,6 +173,41 @@ describe('HlsjsPlayback', () => { }) }) + describe('_ready method', () => { + test('call _setup method if HLS.JS internal don\'t exists', () => { + const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' }) + jest.spyOn(playback, '_setup') + playback._ready() + + expect(playback._setup).toHaveBeenCalledTimes(1) + + playback._ready() + expect(playback._setup).toHaveBeenCalledTimes(1) + }) + + test('update _isReadyState flag value to true', () => { + const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' }) + + expect(playback._isReadyState).toBeFalsy() + + playback._ready() + + expect(playback._isReadyState).toBeTruthy() + }) + + test('triggers PLAYBACK_READY event', done => { + const cb = jest.fn() + const playback = new HlsjsPlayback({ src: 'http://clappr.io/video.m3u8' }) + + playback.listenTo(playback, Events.PLAYBACK_READY, cb) + playback.listenTo(playback, Events.PLAYBACK_READY, () => { + expect(cb).toHaveBeenCalledTimes(1) + done() + }) + playback._ready() + }) + }) + describe('play method', () => { test('calls this._hls.loadSource if _manifestParsed flag and options.hlsPlayback.preload are falsy', () => { const playback = new HlsjsPlayback({ src: 'http://clappr.io/foo.m3u8', hlsPlayback: { preload: true } })