return
}
+ this._clearTimeout()
+
if (this._config.animation) {
this._element.classList.add(CLASS_NAME_FADE)
}
}
dispose() {
- clearTimeout(this._timeout)
- this._timeout = null
+ this._clearTimeout()
if (this._element.classList.contains(CLASS_NAME_SHOW)) {
this._element.classList.remove(CLASS_NAME_SHOW)
)
}
+ _clearTimeout() {
+ clearTimeout(this._timeout)
+ this._timeout = null
+ }
+
// Static
static jQueryInterface(config) {
toast.show()
})
+
+ it('should clear timeout if toast is shown again before it is hidden', done => {
+ fixtureEl.innerHTML = [
+ '<div class="toast">',
+ ' <div class="toast-body">',
+ ' a simple toast',
+ ' </div>',
+ '</div>'
+ ].join('')
+
+ const toastEl = fixtureEl.querySelector('.toast')
+ const toast = new Toast(toastEl)
+
+ setTimeout(() => {
+ toast._config.autohide = false
+ toastEl.addEventListener('shown.bs.toast', () => {
+ expect(toast._clearTimeout).toHaveBeenCalled()
+ expect(toast._timeout).toBeNull()
+ done()
+ })
+ toast.show()
+ }, toast._config.delay / 2)
+
+ spyOn(toast, '_clearTimeout').and.callThrough()
+
+ toast.show()
+ })
})
describe('hide', () => {