Skip to content

Commit f4d554d

Browse files
committed
add catch to avoid error in windows
1 parent 527dd5a commit f4d554d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/devextreme/js/__internal/ui/themes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function readThemeMarker(): string | null {
6060
return null;
6161
}
6262
return result.substr(THEME_MARKER_PREFIX.length);
63+
} catch (e) {
64+
return null;
6365
} finally {
6466
element.remove();
6567
}

packages/devextreme/testing/tests/DevExpress.ui/themes.tests.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,39 @@ QUnit.module('initialized method', (hooks) => {
825825
});
826826
});
827827
});
828+
829+
QUnit.module('readThemeMarker error handling', () => {
830+
test('readThemeMarker returns null when getComputedStyle throws an error', function(assert) {
831+
const done = assert.async();
832+
const originalGetComputedStyle = window.getComputedStyle;
833+
window.getComputedStyle = function() { throw new Error('getComputedStyle fails'); };
834+
835+
try {
836+
themes.resetTheme();
837+
const value = themes.current();
838+
assert.strictEqual(value, null, 'current() returns null on getComputedStyle error');
839+
} finally {
840+
window.getComputedStyle = originalGetComputedStyle;
841+
done();
842+
}
843+
});
844+
845+
test('waitForThemeLoad resolves even if getComputedStyle continuously throws', function(assert) {
846+
const done = assert.async();
847+
const originalGetComputedStyle = window.getComputedStyle;
848+
window.getComputedStyle = function() { throw new Error('boom'); };
849+
850+
const TEST_TIMEOUT = 30;
851+
themes.resetTheme();
852+
themes.setDefaultTimeout(TEST_TIMEOUT);
853+
854+
themes.ready(() => {
855+
assert.strictEqual(themes.current(), null, 'theme remains null after timeout with errors');
856+
window.getComputedStyle = originalGetComputedStyle;
857+
themes.setDefaultTimeout(defaultTimeout);
858+
done();
859+
});
860+
861+
themes.waitForThemeLoad('some.nonexistent.theme');
862+
});
863+
});

0 commit comments

Comments
 (0)