diff options
Diffstat (limited to 'js/tests/unit/toast.spec.js')
| -rw-r--r-- | js/tests/unit/toast.spec.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/js/tests/unit/toast.spec.js b/js/tests/unit/toast.spec.js index cc873d1fe..d298dc993 100644 --- a/js/tests/unit/toast.spec.js +++ b/js/tests/unit/toast.spec.js @@ -20,7 +20,24 @@ describe('Toast', () => { }) }) + describe('DATA_KEY', () => { + it('should return plugin data key', () => { + expect(Toast.DATA_KEY).toEqual('bs.toast') + }) + }) + describe('constructor', () => { + it('should take care of element either passed as a CSS selector or DOM element', () => { + fixtureEl.innerHTML = '<div class="toast"></div>' + + const toastEl = fixtureEl.querySelector('.toast') + const toastBySelector = new Toast('.toast') + const toastByElement = new Toast(toastEl) + + expect(toastBySelector._element).toEqual(toastEl) + expect(toastByElement._element).toEqual(toastEl) + }) + it('should allow to config in js', done => { fixtureEl.innerHTML = [ '<div class="toast">', @@ -274,13 +291,18 @@ describe('Toast', () => { fixtureEl.innerHTML = '<div></div>' const toastEl = fixtureEl.querySelector('div') + spyOn(toastEl, 'addEventListener').and.callThrough() + spyOn(toastEl, 'removeEventListener').and.callThrough() + const toast = new Toast(toastEl) expect(Toast.getInstance(toastEl)).toBeDefined() + expect(toastEl.addEventListener).toHaveBeenCalledWith('click', jasmine.any(Function), jasmine.any(Boolean)) toast.dispose() expect(Toast.getInstance(toastEl)).toBeNull() + expect(toastEl.removeEventListener).toHaveBeenCalledWith('click', jasmine.any(Function), jasmine.any(Boolean)) }) it('should allow to destroy toast and hide it before that', done => { @@ -368,11 +390,9 @@ describe('Toast', () => { jQueryMock.fn.toast = Toast.jQueryInterface jQueryMock.elements = [div] - try { + expect(() => { jQueryMock.fn.toast.call(jQueryMock, action) - } catch (error) { - expect(error.message).toEqual(`No method named "${action}"`) - } + }).toThrowError(TypeError, `No method named "${action}"`) }) }) |
