mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 00:24:03 +02:00
tests: minor cleanup (#35138)
* tests: minor cleanup * tests: use the util noop function
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import Alert from '../../src/alert'
|
import Alert from '../../src/alert'
|
||||||
import { getTransitionDurationFromElement } from '../../src/util/index'
|
import { getTransitionDurationFromElement } from '../../src/util/index'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Alert', () => {
|
describe('Alert', () => {
|
||||||
|
@@ -1,11 +1,5 @@
|
|||||||
import Button from '../../src/button'
|
import Button from '../../src/button'
|
||||||
|
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'
|
||||||
/** Test helpers */
|
|
||||||
import {
|
|
||||||
getFixture,
|
|
||||||
clearFixture,
|
|
||||||
jQueryMock
|
|
||||||
} from '../helpers/fixture'
|
|
||||||
|
|
||||||
describe('Button', () => {
|
describe('Button', () => {
|
||||||
let fixtureEl
|
let fixtureEl
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
import Carousel from '../../src/carousel'
|
import Carousel from '../../src/carousel'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
import * as util from '../../src/util'
|
import { isRTL, noop } from '../../src/util/index'
|
||||||
|
|
||||||
describe('Carousel', () => {
|
describe('Carousel', () => {
|
||||||
const { Simulator, PointerEvent } = window
|
const { Simulator, PointerEvent } = window
|
||||||
@@ -331,7 +329,7 @@ describe('Carousel', () => {
|
|||||||
|
|
||||||
// Headless browser does not support touch events, so need to fake it
|
// Headless browser does not support touch events, so need to fake it
|
||||||
// to test that touch events are add properly.
|
// to test that touch events are add properly.
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
const carousel = new Carousel(carouselEl)
|
const carousel = new Carousel(carouselEl)
|
||||||
|
|
||||||
expect(carousel._addTouchEventListeners).toHaveBeenCalled()
|
expect(carousel._addTouchEventListeners).toHaveBeenCalled()
|
||||||
@@ -344,7 +342,7 @@ describe('Carousel', () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
document.head.append(stylesCarousel)
|
document.head.append(stylesCarousel)
|
||||||
Simulator.setType('pointer')
|
Simulator.setType('pointer')
|
||||||
|
|
||||||
@@ -389,7 +387,7 @@ describe('Carousel', () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
document.head.append(stylesCarousel)
|
document.head.append(stylesCarousel)
|
||||||
Simulator.setType('pointer')
|
Simulator.setType('pointer')
|
||||||
|
|
||||||
@@ -431,7 +429,7 @@ describe('Carousel', () => {
|
|||||||
it('should allow swiperight and call _slide (prev) with touch events', done => {
|
it('should allow swiperight and call _slide (prev) with touch events', done => {
|
||||||
Simulator.setType('touch')
|
Simulator.setType('touch')
|
||||||
clearPointerEvents()
|
clearPointerEvents()
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
|
|
||||||
fixtureEl.innerHTML = [
|
fixtureEl.innerHTML = [
|
||||||
'<div class="carousel" data-bs-interval="false">',
|
'<div class="carousel" data-bs-interval="false">',
|
||||||
@@ -470,7 +468,7 @@ describe('Carousel', () => {
|
|||||||
it('should allow swipeleft and call _slide (next) with touch events', done => {
|
it('should allow swipeleft and call _slide (next) with touch events', done => {
|
||||||
Simulator.setType('touch')
|
Simulator.setType('touch')
|
||||||
clearPointerEvents()
|
clearPointerEvents()
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
|
|
||||||
fixtureEl.innerHTML = [
|
fixtureEl.innerHTML = [
|
||||||
'<div class="carousel" data-bs-interval="false">',
|
'<div class="carousel" data-bs-interval="false">',
|
||||||
@@ -510,7 +508,7 @@ describe('Carousel', () => {
|
|||||||
it('should not slide when swiping and carousel is sliding', done => {
|
it('should not slide when swiping and carousel is sliding', done => {
|
||||||
Simulator.setType('touch')
|
Simulator.setType('touch')
|
||||||
clearPointerEvents()
|
clearPointerEvents()
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
|
|
||||||
fixtureEl.innerHTML = [
|
fixtureEl.innerHTML = [
|
||||||
'<div class="carousel" data-bs-interval="false">',
|
'<div class="carousel" data-bs-interval="false">',
|
||||||
@@ -553,7 +551,7 @@ describe('Carousel', () => {
|
|||||||
it('should not allow pinch with touch events', done => {
|
it('should not allow pinch with touch events', done => {
|
||||||
Simulator.setType('touch')
|
Simulator.setType('touch')
|
||||||
clearPointerEvents()
|
clearPointerEvents()
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
|
|
||||||
fixtureEl.innerHTML = '<div class="carousel" data-bs-interval="false"></div>'
|
fixtureEl.innerHTML = '<div class="carousel" data-bs-interval="false"></div>'
|
||||||
|
|
||||||
@@ -978,7 +976,7 @@ describe('Carousel', () => {
|
|||||||
const carouselEl = fixtureEl.querySelector('#myCarousel')
|
const carouselEl = fixtureEl.querySelector('#myCarousel')
|
||||||
const carousel = new Carousel(carouselEl)
|
const carousel = new Carousel(carouselEl)
|
||||||
|
|
||||||
carousel._interval = setInterval(() => {}, 10)
|
carousel._interval = setInterval(noop, 10)
|
||||||
|
|
||||||
spyOn(window, 'setInterval').and.callThrough()
|
spyOn(window, 'setInterval').and.callThrough()
|
||||||
spyOn(window, 'clearInterval').and.callThrough()
|
spyOn(window, 'clearInterval').and.callThrough()
|
||||||
@@ -1175,7 +1173,7 @@ describe('Carousel', () => {
|
|||||||
|
|
||||||
const carouselEl = fixtureEl.querySelector('div')
|
const carouselEl = fixtureEl.querySelector('div')
|
||||||
const carousel = new Carousel(carouselEl, {})
|
const carousel = new Carousel(carouselEl, {})
|
||||||
expect(util.isRTL()).toEqual(true, 'rtl has to be true')
|
expect(isRTL()).toEqual(true, 'rtl has to be true')
|
||||||
|
|
||||||
expect(carousel._directionToOrder('left')).toEqual('prev')
|
expect(carousel._directionToOrder('left')).toEqual('prev')
|
||||||
expect(carousel._directionToOrder('prev')).toEqual('prev')
|
expect(carousel._directionToOrder('prev')).toEqual('prev')
|
||||||
@@ -1243,7 +1241,7 @@ describe('Carousel', () => {
|
|||||||
|
|
||||||
// Headless browser does not support touch events, so need to fake it
|
// Headless browser does not support touch events, so need to fake it
|
||||||
// to test that touch events are add/removed properly.
|
// to test that touch events are add/removed properly.
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
|
|
||||||
const carousel = new Carousel(carouselEl)
|
const carousel = new Carousel(carouselEl)
|
||||||
|
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import Collapse from '../../src/collapse'
|
import Collapse from '../../src/collapse'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Collapse', () => {
|
describe('Collapse', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import Data from '../../../src/dom/data'
|
import Data from '../../../src/dom/data'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture } from '../../helpers/fixture'
|
import { getFixture, clearFixture } from '../../helpers/fixture'
|
||||||
|
|
||||||
describe('Data', () => {
|
describe('Data', () => {
|
||||||
@@ -90,8 +88,8 @@ describe('Data', () => {
|
|||||||
expect(Data.get(div, TEST_KEY)).toBeNull()
|
expect(Data.get(div, TEST_KEY)).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
it('should console.error a message if called with multiple keys', () => {
|
it('should console.error a message if called with multiple keys', () => {
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.error = jasmine.createSpy('console.error')
|
console.error = jasmine.createSpy('console.error')
|
||||||
|
|
||||||
const data = { ...TEST_DATA }
|
const data = { ...TEST_DATA }
|
||||||
@@ -103,4 +101,5 @@ describe('Data', () => {
|
|||||||
expect(console.error).toHaveBeenCalled()
|
expect(console.error).toHaveBeenCalled()
|
||||||
expect(Data.get(div, UNKNOWN_KEY)).toBe(null)
|
expect(Data.get(div, UNKNOWN_KEY)).toBe(null)
|
||||||
})
|
})
|
||||||
|
/* eslint-enable no-console */
|
||||||
})
|
})
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import EventHandler from '../../../src/dom/event-handler'
|
import EventHandler from '../../../src/dom/event-handler'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture } from '../../helpers/fixture'
|
import { getFixture, clearFixture } from '../../helpers/fixture'
|
||||||
|
|
||||||
describe('EventHandler', () => {
|
describe('EventHandler', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import Manipulator from '../../../src/dom/manipulator'
|
import Manipulator from '../../../src/dom/manipulator'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture } from '../../helpers/fixture'
|
import { getFixture, clearFixture } from '../../helpers/fixture'
|
||||||
|
|
||||||
describe('Manipulator', () => {
|
describe('Manipulator', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import SelectorEngine from '../../../src/dom/selector-engine'
|
import SelectorEngine from '../../../src/dom/selector-engine'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture } from '../../helpers/fixture'
|
import { getFixture, clearFixture } from '../../helpers/fixture'
|
||||||
|
|
||||||
describe('SelectorEngine', () => {
|
describe('SelectorEngine', () => {
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import Dropdown from '../../src/dropdown'
|
import Dropdown from '../../src/dropdown'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
import { noop } from '../../src/util'
|
import { noop } from '../../src/util/index'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Dropdown', () => {
|
describe('Dropdown', () => {
|
||||||
@@ -225,7 +223,7 @@ describe('Dropdown', () => {
|
|||||||
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
|
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
|
||||||
const dropdown = new Dropdown(btnDropdown)
|
const dropdown = new Dropdown(btnDropdown)
|
||||||
|
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
spyOn(EventHandler, 'on')
|
spyOn(EventHandler, 'on')
|
||||||
spyOn(EventHandler, 'off')
|
spyOn(EventHandler, 'off')
|
||||||
|
|
||||||
@@ -891,7 +889,7 @@ describe('Dropdown', () => {
|
|||||||
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
|
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
|
||||||
const dropdown = new Dropdown(btnDropdown)
|
const dropdown = new Dropdown(btnDropdown)
|
||||||
|
|
||||||
document.documentElement.ontouchstart = () => {}
|
document.documentElement.ontouchstart = noop
|
||||||
spyOn(EventHandler, 'off')
|
spyOn(EventHandler, 'off')
|
||||||
|
|
||||||
btnDropdown.addEventListener('shown.bs.dropdown', () => {
|
btnDropdown.addEventListener('shown.bs.dropdown', () => {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
/* eslint-env jquery */
|
/* eslint-env jquery */
|
||||||
|
|
||||||
import Alert from '../../src/alert'
|
import Alert from '../../src/alert'
|
||||||
import Button from '../../src/button'
|
import Button from '../../src/button'
|
||||||
import Carousel from '../../src/carousel'
|
import Carousel from '../../src/carousel'
|
||||||
@@ -11,8 +12,6 @@ import ScrollSpy from '../../src/scrollspy'
|
|||||||
import Tab from '../../src/tab'
|
import Tab from '../../src/tab'
|
||||||
import Toast from '../../src/toast'
|
import Toast from '../../src/toast'
|
||||||
import Tooltip from '../../src/tooltip'
|
import Tooltip from '../../src/tooltip'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture } from '../helpers/fixture'
|
import { getFixture, clearFixture } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('jQuery', () => {
|
describe('jQuery', () => {
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import Modal from '../../src/modal'
|
import Modal from '../../src/modal'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
import ScrollBarHelper from '../../src/util/scrollbar'
|
import ScrollBarHelper from '../../src/util/scrollbar'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Modal', () => {
|
describe('Modal', () => {
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
import Offcanvas from '../../src/offcanvas'
|
import Offcanvas from '../../src/offcanvas'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
import { isVisible } from '../../src/util'
|
import { isVisible } from '../../src/util/index'
|
||||||
import ScrollBarHelper from '../../src/util/scrollbar'
|
import ScrollBarHelper from '../../src/util/scrollbar'
|
||||||
|
|
||||||
describe('Offcanvas', () => {
|
describe('Offcanvas', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import Popover from '../../src/popover'
|
import Popover from '../../src/popover'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Popover', () => {
|
describe('Popover', () => {
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
import ScrollSpy from '../../src/scrollspy'
|
import ScrollSpy from '../../src/scrollspy'
|
||||||
import Manipulator from '../../src/dom/manipulator'
|
import Manipulator from '../../src/dom/manipulator'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
|
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('ScrollSpy', () => {
|
describe('ScrollSpy', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import Tab from '../../src/tab'
|
import Tab from '../../src/tab'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'
|
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Tab', () => {
|
describe('Tab', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import Toast from '../../src/toast'
|
import Toast from '../../src/toast'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
|
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Toast', () => {
|
describe('Toast', () => {
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import Tooltip from '../../src/tooltip'
|
import Tooltip from '../../src/tooltip'
|
||||||
import EventHandler from '../../src/dom/event-handler'
|
import EventHandler from '../../src/dom/event-handler'
|
||||||
import { noop } from '../../src/util/index'
|
import { noop } from '../../src/util/index'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||||
|
|
||||||
describe('Tooltip', () => {
|
describe('Tooltip', () => {
|
||||||
|
@@ -1,6 +1,4 @@
|
|||||||
import * as Util from '../../../src/util/index'
|
import * as Util from '../../../src/util/index'
|
||||||
|
|
||||||
/** Test helpers */
|
|
||||||
import { clearFixture, getFixture } from '../../helpers/fixture'
|
import { clearFixture, getFixture } from '../../helpers/fixture'
|
||||||
|
|
||||||
describe('Util', () => {
|
describe('Util', () => {
|
||||||
|
Reference in New Issue
Block a user