Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test
Browse files Browse the repository at this point in the history
misteroneill committed Oct 17, 2017
1 parent 4bbec34 commit 51b57d4
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
@@ -1621,6 +1621,64 @@ QUnit.test('src_ does not call loadTech is name is titleCaseEquals', function(as
assert.equal(loadTechCalled, 0, 'loadTech was not called');
});

QUnit.test('subsequent calls to src() will put the player in a non-ready state, so calling ready() immediately after will correctly wait until the new source is set', function(assert) {
const tag = TestHelpers.makeTag();
const player = videojs(tag);
const onReadySpy = sinon.spy();
const readySpy = sinon.spy();

player.on('ready', onReadySpy);
player.ready(readySpy);

assert.equal(onReadySpy.callCount, 0, 'no readiness yet...');
assert.equal(readySpy.callCount, 0, 'no readiness yet...');

this.clock.tick(1);

assert.equal(onReadySpy.callCount, 1, 'saw an initial "ready"');
assert.equal(readySpy.callCount, 1, 'saw an initial ready() callback');

player.src({
src: 'http://example.com/video.mp4',
type: 'video/mp4'
});

player.ready(readySpy);

assert.equal(onReadySpy.callCount, 1, 'did not see a "ready" because source setting is async');
assert.equal(readySpy.callCount, 1, 'did not see a ready() callback because source setting is async');

this.clock.tick(1);

assert.equal(onReadySpy.callCount, 1, 'did not see a "ready" because middleware queues up another async operation');
assert.equal(readySpy.callCount, 1, 'did not see a ready() callback because middleware queues up another async operation');

this.clock.tick(1);

assert.equal(onReadySpy.callCount, 2, 'saw second "ready" because source setting and tech selection are complete');
assert.equal(readySpy.callCount, 2, 'saw second ready() callback because source setting and tech selection are complete');

player.src({
src: 'http://example.com/video2.mp4',
type: 'video/mp4'
});

player.ready(readySpy);

assert.equal(onReadySpy.callCount, 2, 'did not see a "ready" because source setting is async');
assert.equal(readySpy.callCount, 2, 'did not see a ready() callback because source setting is async');

this.clock.tick(1);

assert.equal(onReadySpy.callCount, 2, 'did not see a "ready" because middleware queues up another async operation');
assert.equal(readySpy.callCount, 2, 'did not see a ready() callback because middleware queues up another async operation');

this.clock.tick(1);

assert.equal(onReadySpy.callCount, 3, 'saw third "ready" because source setting and tech selection are complete');
assert.equal(readySpy.callCount, 3, 'saw third ready() callback because source setting and tech selection are complete');
});

QUnit.test('options: plugins', function(assert) {
const optionsSpy = sinon.spy();

0 comments on commit 51b57d4

Please sign in to comment.