Skip to content

Commit

Permalink
tests: minor cleanup (twbs#35138)
Browse files Browse the repository at this point in the history
* tests: minor cleanup

* tests: use the util noop function
  • Loading branch information
XhmikosR authored Oct 8, 2021
1 parent eb0f705 commit a260967
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 57 deletions.
2 changes: 0 additions & 2 deletions js/tests/unit/alert.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Alert from '../../src/alert'
import { getTransitionDurationFromElement } from '../../src/util/index'

/** Test helpers */
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'

describe('Alert', () => {
Expand Down
8 changes: 1 addition & 7 deletions js/tests/unit/button.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import Button from '../../src/button'

/** Test helpers */
import {
getFixture,
clearFixture,
jQueryMock
} from '../helpers/fixture'
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'

describe('Button', () => {
let fixtureEl
Expand Down
24 changes: 11 additions & 13 deletions js/tests/unit/carousel.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Carousel from '../../src/carousel'
import EventHandler from '../../src/dom/event-handler'

/** Test helpers */
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
import * as util from '../../src/util'
import { isRTL, noop } from '../../src/util/index'

describe('Carousel', () => {
const { Simulator, PointerEvent } = window
Expand Down Expand Up @@ -331,7 +329,7 @@ describe('Carousel', () => {

// Headless browser does not support touch events, so need to fake it
// to test that touch events are add properly.
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop
const carousel = new Carousel(carouselEl)

expect(carousel._addTouchEventListeners).toHaveBeenCalled()
Expand All @@ -344,7 +342,7 @@ describe('Carousel', () => {
return
}

document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop
document.head.append(stylesCarousel)
Simulator.setType('pointer')

Expand Down Expand Up @@ -389,7 +387,7 @@ describe('Carousel', () => {
return
}

document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop
document.head.append(stylesCarousel)
Simulator.setType('pointer')

Expand Down Expand Up @@ -431,7 +429,7 @@ describe('Carousel', () => {
it('should allow swiperight and call _slide (prev) with touch events', done => {
Simulator.setType('touch')
clearPointerEvents()
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop

fixtureEl.innerHTML = [
'<div class="carousel" data-bs-interval="false">',
Expand Down Expand Up @@ -470,7 +468,7 @@ describe('Carousel', () => {
it('should allow swipeleft and call _slide (next) with touch events', done => {
Simulator.setType('touch')
clearPointerEvents()
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop

fixtureEl.innerHTML = [
'<div class="carousel" data-bs-interval="false">',
Expand Down Expand Up @@ -510,7 +508,7 @@ describe('Carousel', () => {
it('should not slide when swiping and carousel is sliding', done => {
Simulator.setType('touch')
clearPointerEvents()
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop

fixtureEl.innerHTML = [
'<div class="carousel" data-bs-interval="false">',
Expand Down Expand Up @@ -553,7 +551,7 @@ describe('Carousel', () => {
it('should not allow pinch with touch events', done => {
Simulator.setType('touch')
clearPointerEvents()
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop

fixtureEl.innerHTML = '<div class="carousel" data-bs-interval="false"></div>'

Expand Down Expand Up @@ -978,7 +976,7 @@ describe('Carousel', () => {
const carouselEl = fixtureEl.querySelector('#myCarousel')
const carousel = new Carousel(carouselEl)

carousel._interval = setInterval(() => {}, 10)
carousel._interval = setInterval(noop, 10)

spyOn(window, 'setInterval').and.callThrough()
spyOn(window, 'clearInterval').and.callThrough()
Expand Down Expand Up @@ -1175,7 +1173,7 @@ describe('Carousel', () => {

const carouselEl = fixtureEl.querySelector('div')
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('prev')).toEqual('prev')
Expand Down Expand Up @@ -1243,7 +1241,7 @@ describe('Carousel', () => {

// Headless browser does not support touch events, so need to fake it
// to test that touch events are add/removed properly.
document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop

const carousel = new Carousel(carouselEl)

Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/collapse.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Collapse from '../../src/collapse'
import EventHandler from '../../src/dom/event-handler'

/** Test helpers */
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'

describe('Collapse', () => {
Expand Down
5 changes: 2 additions & 3 deletions js/tests/unit/dom/data.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Data from '../../../src/dom/data'

/** Test helpers */
import { getFixture, clearFixture } from '../../helpers/fixture'

describe('Data', () => {
Expand Down Expand Up @@ -90,8 +88,8 @@ describe('Data', () => {
expect(Data.get(div, TEST_KEY)).toBeNull()
})

/* eslint-disable no-console */
it('should console.error a message if called with multiple keys', () => {
/* eslint-disable no-console */
console.error = jasmine.createSpy('console.error')

const data = { ...TEST_DATA }
Expand All @@ -103,4 +101,5 @@ describe('Data', () => {
expect(console.error).toHaveBeenCalled()
expect(Data.get(div, UNKNOWN_KEY)).toBe(null)
})
/* eslint-enable no-console */
})
2 changes: 0 additions & 2 deletions js/tests/unit/dom/event-handler.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import EventHandler from '../../../src/dom/event-handler'

/** Test helpers */
import { getFixture, clearFixture } from '../../helpers/fixture'

describe('EventHandler', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/dom/manipulator.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Manipulator from '../../../src/dom/manipulator'

/** Test helpers */
import { getFixture, clearFixture } from '../../helpers/fixture'

describe('Manipulator', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/dom/selector-engine.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import SelectorEngine from '../../../src/dom/selector-engine'

/** Test helpers */
import { getFixture, clearFixture } from '../../helpers/fixture'

describe('SelectorEngine', () => {
Expand Down
8 changes: 3 additions & 5 deletions js/tests/unit/dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Dropdown from '../../src/dropdown'
import EventHandler from '../../src/dom/event-handler'
import { noop } from '../../src/util'

/** Test helpers */
import { noop } from '../../src/util/index'
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'

describe('Dropdown', () => {
Expand Down Expand Up @@ -225,7 +223,7 @@ describe('Dropdown', () => {
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown)

document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop
spyOn(EventHandler, 'on')
spyOn(EventHandler, 'off')

Expand Down Expand Up @@ -891,7 +889,7 @@ describe('Dropdown', () => {
const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]')
const dropdown = new Dropdown(btnDropdown)

document.documentElement.ontouchstart = () => {}
document.documentElement.ontouchstart = noop
spyOn(EventHandler, 'off')

btnDropdown.addEventListener('shown.bs.dropdown', () => {
Expand Down
3 changes: 1 addition & 2 deletions js/tests/unit/jquery.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env jquery */

import Alert from '../../src/alert'
import Button from '../../src/button'
import Carousel from '../../src/carousel'
Expand All @@ -11,8 +12,6 @@ import ScrollSpy from '../../src/scrollspy'
import Tab from '../../src/tab'
import Toast from '../../src/toast'
import Tooltip from '../../src/tooltip'

/** Test helpers */
import { getFixture, clearFixture } from '../helpers/fixture'

describe('jQuery', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/modal.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Modal from '../../src/modal'
import EventHandler from '../../src/dom/event-handler'
import ScrollBarHelper from '../../src/util/scrollbar'

/** Test helpers */
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'

describe('Modal', () => {
Expand Down
4 changes: 1 addition & 3 deletions js/tests/unit/offcanvas.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Offcanvas from '../../src/offcanvas'
import EventHandler from '../../src/dom/event-handler'

/** Test helpers */
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'

describe('Offcanvas', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/popover.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Popover from '../../src/popover'

/** Test helpers */
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'

describe('Popover', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/scrollspy.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ScrollSpy from '../../src/scrollspy'
import Manipulator from '../../src/dom/manipulator'

/** Test helpers */
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'

describe('ScrollSpy', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/tab.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Tab from '../../src/tab'

/** Test helpers */
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'

describe('Tab', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/toast.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Toast from '../../src/toast'

/** Test helpers */
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'

describe('Toast', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Tooltip from '../../src/tooltip'
import EventHandler from '../../src/dom/event-handler'
import { noop } from '../../src/util/index'

/** Test helpers */
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'

describe('Tooltip', () => {
Expand Down
2 changes: 0 additions & 2 deletions js/tests/unit/util/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as Util from '../../../src/util/index'

/** Test helpers */
import { clearFixture, getFixture } from '../../helpers/fixture'

describe('Util', () => {
Expand Down

0 comments on commit a260967

Please sign in to comment.