Commit da7d3ef2 authored by Angelo Gulina's avatar Angelo Gulina

Update check on features object for cases where not defined

parent f964c97c
......@@ -32,7 +32,7 @@ const handleStartupEvents = () => {
action();
-*/
export const waitForCSSLoaded = (action = () => {}) => {
if (!gon.features.startupCss || allLinksLoaded()) {
if (!gon?.features?.startupCss || allLinksLoaded()) {
return new Promise(resolve => {
action();
resolve();
......
......@@ -19,6 +19,26 @@ describe('waitForCSSLoaded', () => {
});
});
describe('when gon features is not provided', () => {
let originalGon;
beforeEach(() => {
originalGon = window.gon;
window.gon = null;
});
afterEach(() => {
window.gon = originalGon;
});
it('should invoke the action right away', async () => {
const events = waitForCSSLoaded(mockedCallback);
await events;
expect(mockedCallback).toHaveBeenCalledTimes(1);
});
});
describe('with startup css disabled', () => {
gon.features = {
startupCss: false,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment