diff options
author | Ben Lertlumprasertkul <benlertlumprasertkul@gmail.com> | 2021-05-11 08:45:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 08:45:57 +0300 |
commit | 052def456845c2147e4e6c99d17bba12fcbee34c (patch) | |
tree | 9f23d9f09941c43fd519bde2498da808a8764635 /js/tests/unit/modal.spec.js | |
parent | 9c3ab6557ec89ae11cc27da1b4680b3e69381edf (diff) |
Remove potential false positive assertions (#33288)
* Remove potential false positive assertions
querySelector() returns null but
expect(document.querySelector('...')).toBeDefined()
tests that the value is not undefined
* Migrated assertions from .toBeDefined() to .not.toBeNull() for .getInstance() calls in tests
* Migrate offcanvas assertions from .toBeDefined() to .not.toBeNull() for .getInstance() call
* convert more cases to not.toBeNull assertions
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Diffstat (limited to 'js/tests/unit/modal.spec.js')
-rw-r--r-- | js/tests/unit/modal.spec.js | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/js/tests/unit/modal.spec.js b/js/tests/unit/modal.spec.js index a09711b349..79f3c4845b 100644 --- a/js/tests/unit/modal.spec.js +++ b/js/tests/unit/modal.spec.js @@ -247,9 +247,9 @@ describe('Modal', () => { modalEl.addEventListener('shown.bs.modal', () => { expect(modalEl.getAttribute('aria-modal')).toEqual('true') expect(modalEl.getAttribute('role')).toEqual('dialog') - expect(modalEl.getAttribute('aria-hidden')).toEqual(null) + expect(modalEl.getAttribute('aria-hidden')).toBeNull() expect(modalEl.style.display).toEqual('block') - expect(document.querySelector('.modal-backdrop')).toBeDefined() + expect(document.querySelector('.modal-backdrop')).not.toBeNull() done() }) @@ -271,7 +271,7 @@ describe('Modal', () => { modalEl.addEventListener('shown.bs.modal', () => { expect(modalEl.getAttribute('aria-modal')).toEqual('true') expect(modalEl.getAttribute('role')).toEqual('dialog') - expect(modalEl.getAttribute('aria-hidden')).toEqual(null) + expect(modalEl.getAttribute('aria-hidden')).toBeNull() expect(modalEl.style.display).toEqual('block') expect(document.querySelector('.modal-backdrop')).toBeNull() done() @@ -292,7 +292,7 @@ describe('Modal', () => { modalEl.addEventListener('shown.bs.modal', () => { const dynamicModal = document.getElementById(id) - expect(dynamicModal).toBeDefined() + expect(dynamicModal).not.toBeNull() dynamicModal.parentNode.removeChild(dynamicModal) done() }) @@ -763,8 +763,8 @@ describe('Modal', () => { }) modalEl.addEventListener('hidden.bs.modal', () => { - expect(modalEl.getAttribute('aria-modal')).toEqual(null) - expect(modalEl.getAttribute('role')).toEqual(null) + expect(modalEl.getAttribute('aria-modal')).toBeNull() + expect(modalEl.getAttribute('role')).toBeNull() expect(modalEl.getAttribute('aria-hidden')).toEqual('true') expect(modalEl.style.display).toEqual('none') expect(document.querySelector('.modal-backdrop')).toBeNull() @@ -785,8 +785,8 @@ describe('Modal', () => { }) modalEl.addEventListener('hidden.bs.modal', () => { - expect(modalEl.getAttribute('aria-modal')).toEqual(null) - expect(modalEl.getAttribute('role')).toEqual(null) + expect(modalEl.getAttribute('aria-modal')).toBeNull() + expect(modalEl.getAttribute('role')).toBeNull() expect(modalEl.getAttribute('aria-hidden')).toEqual('true') expect(modalEl.style.display).toEqual('none') expect(document.querySelector('.modal-backdrop')).toBeNull() @@ -862,7 +862,7 @@ describe('Modal', () => { modal.dispose() - expect(Modal.getInstance(modalEl)).toEqual(null) + expect(Modal.getInstance(modalEl)).toBeNull() expect(EventHandler.off).toHaveBeenCalledTimes(4) }) }) @@ -895,18 +895,18 @@ describe('Modal', () => { modalEl.addEventListener('shown.bs.modal', () => { expect(modalEl.getAttribute('aria-modal')).toEqual('true') expect(modalEl.getAttribute('role')).toEqual('dialog') - expect(modalEl.getAttribute('aria-hidden')).toEqual(null) + expect(modalEl.getAttribute('aria-hidden')).toBeNull() expect(modalEl.style.display).toEqual('block') - expect(document.querySelector('.modal-backdrop')).toBeDefined() + expect(document.querySelector('.modal-backdrop')).not.toBeNull() setTimeout(() => trigger.click(), 10) }) modalEl.addEventListener('hidden.bs.modal', () => { - expect(modalEl.getAttribute('aria-modal')).toEqual(null) - expect(modalEl.getAttribute('role')).toEqual(null) + expect(modalEl.getAttribute('aria-modal')).toBeNull() + expect(modalEl.getAttribute('role')).toBeNull() expect(modalEl.getAttribute('aria-hidden')).toEqual('true') expect(modalEl.style.display).toEqual('none') - expect(document.querySelector('.modal-backdrop')).toEqual(null) + expect(document.querySelector('.modal-backdrop')).toBeNull() done() }) @@ -947,9 +947,9 @@ describe('Modal', () => { modalEl.addEventListener('shown.bs.modal', () => { expect(modalEl.getAttribute('aria-modal')).toEqual('true') expect(modalEl.getAttribute('role')).toEqual('dialog') - expect(modalEl.getAttribute('aria-hidden')).toEqual(null) + expect(modalEl.getAttribute('aria-hidden')).toBeNull() expect(modalEl.style.display).toEqual('block') - expect(document.querySelector('.modal-backdrop')).toBeDefined() + expect(document.querySelector('.modal-backdrop')).not.toBeNull() expect(Event.prototype.preventDefault).toHaveBeenCalled() done() }) @@ -1057,7 +1057,7 @@ describe('Modal', () => { jQueryMock.fn.modal.call(jQueryMock) - expect(Modal.getInstance(div)).toBeDefined() + expect(Modal.getInstance(div)).not.toBeNull() }) it('should create a modal with given config', () => { @@ -1073,7 +1073,7 @@ describe('Modal', () => { expect(Modal.prototype.constructor).not.toHaveBeenCalledWith(div, { keyboard: false }) const modal = Modal.getInstance(div) - expect(modal).toBeDefined() + expect(modal).not.toBeNull() expect(modal._config.keyboard).toBe(false) }) @@ -1153,7 +1153,7 @@ describe('Modal', () => { const div = fixtureEl.querySelector('div') - expect(Modal.getInstance(div)).toEqual(null) + expect(Modal.getInstance(div)).toBeNull() }) }) }) |