Skip to content

Commit c6efbd6

Browse files
committed
test: Fix test failures triggered with --no-babel
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
1 parent 3a7d5b2 commit c6efbd6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/media/media_source_engine_unit.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,15 @@ describe('MediaSourceEngine', () => {
181181
shaka.media.MediaSourceEngine.createObjectURL =
182182
Util.spyFunc(createObjectURLSpy);
183183

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

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

0 commit comments

Comments
 (0)