diff options
| author | Nils K <[email protected]> | 2020-12-21 13:32:11 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-21 14:32:11 +0200 |
| commit | 2d46e47464d15182c44a7d92c8f2476e70f4434e (patch) | |
| tree | 39be89ab0696d4508df55ecc46db23f3e7df0ce1 /js/tests | |
| parent | 44667d89fa1bf8de15db57fad43696c62860e288 (diff) | |
| download | bootstrap-2d46e47464d15182c44a7d92c8f2476e70f4434e.tar.xz bootstrap-2d46e47464d15182c44a7d92c8f2476e70f4434e.zip | |
Support Popper virtual elements (#32376)
Adds the ability to use objects implementing the virtual element interface as the value for the reference option of a dropdown config.
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/unit/dropdown.spec.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/js/tests/unit/dropdown.spec.js b/js/tests/unit/dropdown.spec.js index d2171f369..ba1d0f443 100644 --- a/js/tests/unit/dropdown.spec.js +++ b/js/tests/unit/dropdown.spec.js @@ -367,6 +367,58 @@ describe('Dropdown', () => { dropdown.toggle() }) + it('should toggle a dropdown with a valid virtual element reference', done => { + fixtureEl.innerHTML = [ + '<div class="dropdown">', + ' <button class="btn dropdown-toggle visually-hidden" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>', + ' <div class="dropdown-menu">', + ' <a class="dropdown-item" href="#">Secondary link</a>', + ' </div>', + '</div>' + ].join('') + + const btnDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]') + const virtualElement = { + getBoundingClientRect() { + return { + width: 0, + height: 0, + top: 0, + right: 0, + bottom: 0, + left: 0 + } + } + } + + expect(() => new Dropdown(btnDropdown, { + reference: {} + })).toThrow() + + expect(() => new Dropdown(btnDropdown, { + reference: { + getBoundingClientRect: 'not-a-function' + } + })).toThrow() + + // use onFirstUpdate as Poppers internal update is executed async + const dropdown = new Dropdown(btnDropdown, { + reference: virtualElement, + popperConfig: { + onFirstUpdate() { + expect(virtualElement.getBoundingClientRect).toHaveBeenCalled() + expect(btnDropdown.classList.contains('show')).toEqual(true) + expect(btnDropdown.getAttribute('aria-expanded')).toEqual('true') + done() + } + } + }) + + spyOn(virtualElement, 'getBoundingClientRect').and.callThrough() + + dropdown.toggle() + }) + it('should not toggle a dropdown if the element is disabled', done => { fixtureEl.innerHTML = [ '<div class="dropdown">', |
