You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

import QUnit from 'qunit';
import xhrFactory from '../src/xhr';
import { useFakeEnvironment } from './test-helpers.js';
import videojs from 'video.js';
QUnit.module('xhr', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.clock = this.env.clock;
this.requests = this.env.requests;
this.xhr = xhrFactory();
},
afterEach() {
this.env.restore();
}
});
QUnit.test('xhr respects beforeRequest', function(assert) {
let defaultOptions = {
url: 'default'
};
this.xhr(defaultOptions);
assert.equal(this.requests.shift().url, 'default', 'url the same without override');
this.xhr.beforeRequest = (options) => {
options.url = 'player';
return options;
};
this.xhr(defaultOptions);
assert.equal(this.requests.shift().url, 'player', 'url changed with player override');
videojs.Hls.xhr.beforeRequest = (options) => {
options.url = 'global';
return options;
};
this.xhr(defaultOptions);
assert.equal(this.requests.shift().url, 'player', 'prioritizes player override');
delete this.xhr.beforeRequest;
this.xhr(defaultOptions);
assert.equal(this.requests.shift().url, 'global', 'url changed with global override');
});