Commit 10b14f85 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'ag-waitforcss-safety' into 'master'

Update check on features object for cases where not defined

See merge request gitlab-org/gitlab!47447
parents 4eea2c9f da7d3ef2
......@@ -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