expect(Util.isElement({})).toBeFalse()
expect(Util.isElement(fixtureEl.querySelectorAll('.test'))).toBeFalse()
})
-
- it('should detect jQuery element', () => {
- fixtureEl.innerHTML = '<div></div>'
-
- const el = fixtureEl.querySelector('div')
- const fakejQuery = {
- 0: el,
- jquery: 'foo'
- }
-
- expect(Util.isElement(fakejQuery)).toBeTrue()
- })
})
describe('getElement', () => {
expect(Util.getElement()).toBeNull()
expect(Util.getElement(null)).toBeNull()
expect(Util.getElement(fixtureEl.querySelectorAll('.test'))).toBeNull()
-
- const fakejQueryObject = {
- 0: el,
- jquery: 'foo'
- }
-
- expect(Util.getElement(fakejQueryObject)).toEqual(el)
})
})
})
})
- describe('getjQuery', () => {
- const fakejQuery = { trigger() {} }
-
- beforeEach(() => {
- Object.defineProperty(window, 'jQuery', {
- value: fakejQuery,
- writable: true
- })
- })
-
- afterEach(() => {
- window.jQuery = undefined
- })
-
- it('should return jQuery object when present', () => {
- expect(Util.getjQuery()).toEqual(fakejQuery)
- })
-
- it('should not return jQuery object when present if data-bs-no-jquery', () => {
- document.body.setAttribute('data-bs-no-jquery', '')
-
- expect(window.jQuery).toEqual(fakejQuery)
- expect(Util.getjQuery()).toBeNull()
-
- document.body.removeAttribute('data-bs-no-jquery')
- })
-
- it('should not return jQuery if not present', () => {
- window.jQuery = undefined
- expect(Util.getjQuery()).toBeNull()
- })
- })
-
describe('onDOMContentLoaded', () => {
it('should execute callbacks when DOMContentLoaded is fired and should not add more than one listener', () => {
const spy = jasmine.createSpy()
})
})
- 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 = Util.noop
- pluginMock.NAME = 'test'
- pluginMock.jQueryInterface = Util.noop
-
- Util.defineJQueryPlugin(pluginMock)
- expect(fakejQuery.fn.test).toEqual(pluginMock.jQueryInterface)
- expect(fakejQuery.fn.test.Constructor).toEqual(pluginMock)
- expect(fakejQuery.fn.test.noConflict).toEqual(jasmine.any(Function))
- })
- })
-
describe('execute', () => {
it('should execute if arg is function', () => {
const spy = jasmine.createSpy('spy')