Skip to content

Commit

Permalink
test: Fix test failures triggered with --no-babel
Browse files Browse the repository at this point in the history
When we run ./test.py --no-babel, Babel is not used to transpile the
tests.  (This restricts test runs to modern browsers and prevents
testing on, say, IE11.)

But Babel seems to have masked some issues with constructor spies.
Jasmine will call your fake callback with "new" if the spy itself is
called with "new", but this means that constructor spies must have
plain function callbacks, not arrow functions.

Change-Id: I936b024504c4173cc29824408e97e5c7d6c591d8
  • Loading branch information
joeyparrish committed Aug 12, 2020
1 parent 3a7d5b2 commit c6efbd6
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/media/media_source_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,15 @@ describe('MediaSourceEngine', () => {
shaka.media.MediaSourceEngine.createObjectURL =
Util.spyFunc(createObjectURLSpy);

const mediaSourceSpy =
jasmine.createSpy('MediaSource').and.callFake(() => {
return mockMediaSource;
});
const mediaSourceSpy = jasmine.createSpy('MediaSource');
// Because this is a fake constructor, it must be callable with "new".
// This will cause jasmine to invoke the callback with "new" as well, so
// the callback must be a "function". This detail is hidden when babel
// transpiles the tests.
// eslint-disable-next-line prefer-arrow-callback, no-restricted-syntax
mediaSourceSpy.and.callFake(function() {
return mockMediaSource;
});
window.MediaSource = Util.spyFunc(mediaSourceSpy);

await mediaSourceEngine.destroy();
Expand Down Expand Up @@ -1158,7 +1163,12 @@ describe('MediaSourceEngine', () => {
function createMockTextEngineCtor() {
const ctor = jasmine.createSpy('TextEngine');
ctor['isTypeSupported'] = () => true;
ctor.and.callFake(() => {
// Because this is a fake constructor, it must be callable with "new".
// This will cause jasmine to invoke the callback with "new" as well, so
// the callback must be a "function". This detail is hidden when babel
// transpiles the tests.
// eslint-disable-next-line prefer-arrow-callback, no-restricted-syntax
ctor.and.callFake(function() {
expect(mockTextEngine).toBeFalsy();
mockTextEngine = jasmine.createSpyObj('TextEngine', [
'initParser', 'destroy', 'appendBuffer', 'remove', 'setTimestampOffset',
Expand Down

0 comments on commit c6efbd6

Please sign in to comment.