Skip to content

Commit

Permalink
test: Test StringUtils both with and without TextDecoder (shaka-proje…
Browse files Browse the repository at this point in the history
…ct#4405)

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 14, 2022
1 parent cfe8af5 commit 381160a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion test/util/string_utils_unit.js
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 381160a

Please sign in to comment.