From c21506d499c682ea5e31107ce264b224c4bb644d Mon Sep 17 00:00:00 2001 From: Sascha Date: Sun, 1 Nov 2020 14:32:36 +0100 Subject: Fix TypeError when Bootstrap is included in `head` (#32024) * extend jquery after domContentLoaded event is fired * add unittest for util onDOMContentLoaded * wait for trigger jquery event after domContentLoaded * remove domcontentready from eventHandler * move istanbul ignore statements to correct line Co-authored-by: XhmikosR --- js/tests/unit/util/index.spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index 541c10baa..f7cc37977 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -394,4 +394,23 @@ describe('Util', () => { expect(Util.getjQuery()).toEqual(null) }) }) + + describe('onDOMContentLoaded', () => { + it('should execute callback when DOMContentLoaded is fired', () => { + const spy = jasmine.createSpy() + spyOnProperty(document, 'readyState').and.returnValue('loading') + Util.onDOMContentLoaded(spy) + window.document.dispatchEvent(new Event('DOMContentLoaded', { + bubbles: true, + cancelable: true + })) + expect(spy).toHaveBeenCalled() + }) + + it('should execute callback if readyState is not "loading"', () => { + const spy = jasmine.createSpy() + Util.onDOMContentLoaded(spy) + expect(spy).toHaveBeenCalled() + }) + }) }) -- cgit v1.2.3