Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/devextreme/js/ui/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ function readThemeMarker() {
return null;
}
return result.substr(THEME_MARKER_PREFIX.length);
} catch(e) {
return null;
} finally {
element.remove();
}
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 = function() { throw new Error('getComputedStyle fails'); };

try {
themes.resetTheme();
const value = themes.current();
assert.strictEqual(value, null, 'current() returns null on getComputedStyle error');
} 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 = function() { throw new Error('boom'); };

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

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

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