Permalink
Browse files

fix(middleware): do a null check in mediator methods (#4913)

  • Loading branch information...
gkatsev committed Jan 31, 2018
1 parent 4404e07 commit 7670db63cd93e52de9d3922097c8294311e54e87
Showing with 18 additions and 1 deletion.
  1. +3 −1 src/js/tech/middleware.js
  2. +15 −0 test/unit/tech/middleware.test.js
@@ -96,7 +96,9 @@ function executeRight(mws, method, value, terminated) {
for (let i = mws.length - 1; i >= 0; i--) {
const mw = mws[i];
mw[method](terminated, value);
if (mw[method]) {
mw[method](terminated, value);
}
}
}
@@ -394,3 +394,18 @@ QUnit.test('setSource will select all middleware of a given type, until src chan
middleware.getMiddleware('video/foo').pop();
middleware.getMiddleware('video/foo').pop();
});
QUnit.test('a middleware without a mediator method will not throw an error', function(assert) {
let pauseCalled = 0;
const myMw = {};
const mwFactory = () => myMw;
const mwFactory2 = () => ({
pause() {
pauseCalled++;
}
});
middleware.mediate([mwFactory(), mwFactory2()], {pause: () => {}}, 'pause');
assert.equal(pauseCalled, 1, 'pauseCalled was called once and no error was thrown');
});

0 comments on commit 7670db6

Please sign in to comment.