diff options
| author | Jeremy Jackson <[email protected]> | 2021-06-29 09:45:45 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-06-29 17:45:45 +0300 |
| commit | d314466a4dd00006ce72f46418a98cce3cfccdb2 (patch) | |
| tree | 1ea1a0f517422ca345a43512d7554f0758548576 /js | |
| parent | b00355de4b4d388dc1064ac541cf1064a7829288 (diff) | |
| download | bootstrap-d314466a4dd00006ce72f46418a98cce3cfccdb2.tar.xz bootstrap-d314466a4dd00006ce72f46418a98cce3cfccdb2.zip | |
Accept argument of different types in the `getInstance` method (#34333)
Diffstat (limited to 'js')
| -rw-r--r-- | js/src/base-component.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/base-component.spec.js | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js index 62aa4adf1..ea0ad6c24 100644 --- a/js/src/base-component.js +++ b/js/src/base-component.js @@ -48,7 +48,7 @@ class BaseComponent { /** Static */ static getInstance(element) { - return Data.get(element, this.DATA_KEY) + return Data.get(getElement(element), this.DATA_KEY) } static getOrCreateInstance(element, config = {}) { diff --git a/js/tests/unit/base-component.spec.js b/js/tests/unit/base-component.spec.js index 1000f2841..b8ec83f12 100644 --- a/js/tests/unit/base-component.spec.js +++ b/js/tests/unit/base-component.spec.js @@ -104,6 +104,20 @@ describe('Base Component', () => { expect(DummyClass.getInstance(element)).toBeInstanceOf(DummyClass) }) + it('should accept element, either passed as a CSS selector, jQuery element, or DOM element', () => { + createInstance() + + expect(DummyClass.getInstance('#foo')).toEqual(instance) + expect(DummyClass.getInstance(element)).toEqual(instance) + + const fakejQueryObject = { + 0: element, + jquery: 'foo' + } + + expect(DummyClass.getInstance(fakejQueryObject)).toEqual(instance) + }) + it('should return null when there is no instance', () => { fixtureEl.innerHTML = '<div></div>' |
