From 85208ae5570aeefe4e94c1ceb29ca3b6ffdf83a1 Mon Sep 17 00:00:00 2001 From: alpadev <2838324+alpadev@users.noreply.github.com> Date: Tue, 8 Dec 2020 07:16:50 +0100 Subject: Refactor components to use a utility function to define jQuery plugins (#32285) * refactor: use an utility function to define jQuery plugins * test: add spec for defineJQueryPlugin utility function * Update .bundlewatch.config.json Co-authored-by: XhmikosR --- js/tests/unit/util/index.spec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'js/tests') diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index ecad59b4d..d4b09bf77 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -413,4 +413,29 @@ describe('Util', () => { expect(spy).toHaveBeenCalled() }) }) + + describe('defineJQueryPlugin', () => { + const fakejQuery = { fn: {} } + + beforeEach(() => { + Object.defineProperty(window, 'jQuery', { + value: fakejQuery, + writable: true + }) + }) + + afterEach(() => { + window.jQuery = undefined + }) + + it('should define a plugin on the jQuery instance', () => { + const pluginMock = function () {} + pluginMock.jQueryInterface = function () {} + + Util.defineJQueryPlugin('test', pluginMock) + expect(fakejQuery.fn.test).toBe(pluginMock.jQueryInterface) + expect(fakejQuery.fn.test.Constructor).toBe(pluginMock) + expect(typeof fakejQuery.fn.test.noConflict).toEqual('function') + }) + }) }) -- cgit v1.2.3