mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 09:04:14 +02:00
JS: tests fixes & standardization of spies usage (#36398)
* Fix carousel spec typo * Change carousel test name in align with testing method * Make the spies declarations the same everywhere
This commit is contained in:
committed by
GitHub
parent
78c0ad8044
commit
d388bd6e1b
@@ -37,8 +37,8 @@ describe('Plugin functions', () => {
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
spyOn(DummyClass2.prototype, 'testMethod')
|
||||
const spyGet = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
const spyTest = spyOn(DummyClass2.prototype, 'testMethod')
|
||||
const componentWrapper = fixtureEl.querySelector('#foo')
|
||||
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
|
||||
const event = createEvent('click')
|
||||
@@ -46,8 +46,8 @@ describe('Plugin functions', () => {
|
||||
enableDismissTrigger(DummyClass2, 'testMethod')
|
||||
btnClose.dispatchEvent(event)
|
||||
|
||||
expect(DummyClass2.getOrCreateInstance).toHaveBeenCalledWith(componentWrapper)
|
||||
expect(DummyClass2.prototype.testMethod).toHaveBeenCalled()
|
||||
expect(spyGet).toHaveBeenCalledWith(componentWrapper)
|
||||
expect(spyTest).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('if data-bs-dismiss="PluginName" hasn\'t got "data-bs-target", "getOrCreateInstance" has to be initialized by closest "plugin.Name" class', () => {
|
||||
@@ -57,8 +57,8 @@ describe('Plugin functions', () => {
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
spyOn(DummyClass2.prototype, 'hide')
|
||||
const spyGet = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
const spyHide = spyOn(DummyClass2.prototype, 'hide')
|
||||
const componentWrapper = fixtureEl.querySelector('#foo')
|
||||
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
|
||||
const event = createEvent('click')
|
||||
@@ -66,8 +66,8 @@ describe('Plugin functions', () => {
|
||||
enableDismissTrigger(DummyClass2)
|
||||
btnClose.dispatchEvent(event)
|
||||
|
||||
expect(DummyClass2.getOrCreateInstance).toHaveBeenCalledWith(componentWrapper)
|
||||
expect(DummyClass2.prototype.hide).toHaveBeenCalled()
|
||||
expect(spyGet).toHaveBeenCalledWith(componentWrapper)
|
||||
expect(spyHide).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('if data-bs-dismiss="PluginName" is disabled, must not trigger function', () => {
|
||||
@@ -77,14 +77,14 @@ describe('Plugin functions', () => {
|
||||
'</div>'
|
||||
].join('')
|
||||
|
||||
spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
const spy = spyOn(DummyClass2, 'getOrCreateInstance').and.callThrough()
|
||||
const btnClose = fixtureEl.querySelector('[data-bs-dismiss="test"]')
|
||||
const event = createEvent('click')
|
||||
|
||||
enableDismissTrigger(DummyClass2)
|
||||
btnClose.dispatchEvent(event)
|
||||
|
||||
expect(DummyClass2.getOrCreateInstance).not.toHaveBeenCalled()
|
||||
expect(spy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should prevent default when the trigger is <a> or <area>', () => {
|
||||
@@ -98,11 +98,11 @@ describe('Plugin functions', () => {
|
||||
const event = createEvent('click')
|
||||
|
||||
enableDismissTrigger(DummyClass2)
|
||||
spyOn(Event.prototype, 'preventDefault').and.callThrough()
|
||||
const spy = spyOn(Event.prototype, 'preventDefault').and.callThrough()
|
||||
|
||||
btnClose.dispatchEvent(event)
|
||||
|
||||
expect(Event.prototype.preventDefault).toHaveBeenCalled()
|
||||
expect(spy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user