Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/devextreme/js/__internal/ui/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function readThemeMarker(): string | null {
let result: string;

try {
if (!window?.getComputedStyle) {
return null;
}
result = window.getComputedStyle(element.get(0)).fontFamily;
if (!result) {
return null;
Expand Down
36 changes: 36 additions & 0 deletions packages/devextreme/testing/tests/DevExpress.ui/themes.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,39 @@ QUnit.module('initialized method', (hooks) => {
});
});
});

QUnit.module('readThemeMarker error handling', () => {
test('readThemeMarker returns null when getComputedStyle throws an error', function(assert) {
const done = assert.async();
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = undefined;

try {
themes.resetTheme();
const value = themes.current();
assert.strictEqual(value, null, 'current() returns null on getComputedStyle being undefined');
} finally {
window.getComputedStyle = originalGetComputedStyle;
done();
}
});

test('waitForThemeLoad resolves even if getComputedStyle continuously throws', function(assert) {
const done = assert.async();
const originalGetComputedStyle = window.getComputedStyle;
window.getComputedStyle = undefined;

const TEST_TIMEOUT = 30;
themes.resetTheme();
themes.setDefaultTimeout(TEST_TIMEOUT);

themes.ready(() => {
assert.strictEqual(themes.current(), null, 'theme remains null after timeout');
window.getComputedStyle = originalGetComputedStyle;
themes.setDefaultTimeout(defaultTimeout);
done();
});

themes.waitForThemeLoad('some.nonexistent.theme');
});
});
Loading