jquery.spec.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-env jquery */
  2. import Alert from '../../src/alert'
  3. import Button from '../../src/button'
  4. import Carousel from '../../src/carousel'
  5. import Collapse from '../../src/collapse'
  6. import Dropdown from '../../src/dropdown'
  7. import Modal from '../../src/modal'
  8. import Popover from '../../src/popover'
  9. import ScrollSpy from '../../src/scrollspy'
  10. import Tab from '../../src/tab'
  11. import Toast from '../../src/toast'
  12. import Tooltip from '../../src/tooltip'
  13. /** Test helpers */
  14. import { getFixture, clearFixture } from '../helpers/fixture'
  15. describe('jQuery', () => {
  16. let fixtureEl
  17. beforeAll(() => {
  18. fixtureEl = getFixture()
  19. })
  20. afterEach(() => {
  21. clearFixture()
  22. })
  23. it('should add all plugins in jQuery', () => {
  24. expect(Alert.jQueryInterface).toEqual(jQuery.fn.alert)
  25. expect(Button.jQueryInterface).toEqual(jQuery.fn.button)
  26. expect(Carousel.jQueryInterface).toEqual(jQuery.fn.carousel)
  27. expect(Collapse.jQueryInterface).toEqual(jQuery.fn.collapse)
  28. expect(Dropdown.jQueryInterface).toEqual(jQuery.fn.dropdown)
  29. expect(Modal.jQueryInterface).toEqual(jQuery.fn.modal)
  30. expect(Popover.jQueryInterface).toEqual(jQuery.fn.popover)
  31. expect(ScrollSpy.jQueryInterface).toEqual(jQuery.fn.scrollspy)
  32. expect(Tab.jQueryInterface).toEqual(jQuery.fn.tab)
  33. expect(Toast.jQueryInterface).toEqual(jQuery.fn.toast)
  34. expect(Tooltip.jQueryInterface).toEqual(jQuery.fn.tooltip)
  35. })
  36. it('should use jQuery event system', done => {
  37. fixtureEl.innerHTML = [
  38. '<div class="alert">',
  39. ' <button type="button" data-bs-dismiss="alert">x</button>',
  40. '</div>'
  41. ].join('')
  42. $(fixtureEl).find('.alert')
  43. .one('closed.bs.alert', () => {
  44. expect($(fixtureEl).find('.alert').length).toEqual(0)
  45. done()
  46. })
  47. $(fixtureEl).find('button').trigger('click')
  48. })
  49. })