Skip to content

Commit

Permalink
test: Test StringUtils both with and without TextDecoder (#4405)
Browse files Browse the repository at this point in the history
Since the TextDecoder fallback is only used on some devices, those
code paths were not tested on other platforms.  This makes the
StringUtil tests execute both with and without TextDecoder.
  • Loading branch information
joeyparrish committed Aug 16, 2022
1 parent f3099df commit 37adeb2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/util/string_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
*/

describe('StringUtils', () => {
describe('with TextDecoder', () => {
if (window.TextDecoder) {
defineStringUtilTests();
}
});

describe('without TextDecoder', () => {
let originalTextDecoder;

beforeAll(() => {
originalTextDecoder = window.TextDecoder;
window['TextDecoder'] = null;
});

afterAll(() => {
window.TextDecoder = originalTextDecoder;
});

defineStringUtilTests();
});
});

function defineStringUtilTests() {
const StringUtils = shaka.util.StringUtils;

it('parses fromUTF8', () => {
Expand Down Expand Up @@ -140,4 +163,4 @@ describe('StringUtils', () => {
expect(StringUtils.fromUTF16(buffer, true).length)
.toBe(buffer.byteLength / 2);
});
});
}

0 comments on commit 37adeb2

Please sign in to comment.