Skip to content

Commit

Permalink
test: cleanup xhr correctly (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Oct 26, 2021
1 parent 5b42d0a commit b992167
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion test/eme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ const resolveReject = (rejectVariable, rejectMessage) => {
});
};

QUnit.module('videojs-contrib-eme eme');
QUnit.module('videojs-contrib-eme eme', {
beforeEach() {
this.origXhr = videojs.xhr;
},
afterEach() {
videojs.xhr = this.origXhr;
}
});

QUnit.test('keystatuseschange triggers keystatuschange on eventBus for each key', function(assert) {
const callCount = {total: 0, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}};
Expand Down
13 changes: 12 additions & 1 deletion test/fairplay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import videojs from 'video.js';
import window from 'global/window';
import { getMockEventBus } from './utils';

QUnit.module('videojs-contrib-eme fairplay');
QUnit.module('videojs-contrib-eme fairplay', {
beforeEach() {
this.origXhr = videojs.xhr;

videojs.xhr = (params, callback) => {
return callback(null, {statusCode: 200}, new Uint8Array([0, 1, 2, 3]).buffer);
};
},
afterEach() {
videojs.xhr = this.origXhr;
}
});

QUnit.test('lifecycle', function(assert) {
assert.expect(23);
Expand Down
7 changes: 7 additions & 0 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ QUnit.module('plugin guard functions', {
}
};

this.origXhr = videojs.xhr;

videojs.xhr = (params, callback) => {
return callback(null, {statusCode: 200}, new Uint8Array([0, 1, 2, 3]).buffer);
};

this.initData1 = new Uint8Array([1, 2, 3]).buffer;
this.initData2 = new Uint8Array([4, 5, 6]).buffer;

Expand Down Expand Up @@ -398,6 +404,7 @@ QUnit.module('plugin guard functions', {
},
afterEach() {
window.navigator.requestMediaKeySystemAccess = this.origRequestMediaKeySystemAccess;
videojs.xhr = this.origXhr;
}
});

Expand Down

0 comments on commit b992167

Please sign in to comment.