mirror of
https://github.com/twbs/bootstrap.git
synced 2025-03-15 15:29:22 +01:00
Accept argument of different types in the getInstance
method (#34333)
This commit is contained in:
parent
b00355de4b
commit
d314466a4d
@ -48,7 +48,7 @@ class BaseComponent {
|
|||||||
/** Static */
|
/** Static */
|
||||||
|
|
||||||
static getInstance(element) {
|
static getInstance(element) {
|
||||||
return Data.get(element, this.DATA_KEY)
|
return Data.get(getElement(element), this.DATA_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getOrCreateInstance(element, config = {}) {
|
static getOrCreateInstance(element, config = {}) {
|
||||||
|
@ -104,6 +104,20 @@ describe('Base Component', () => {
|
|||||||
expect(DummyClass.getInstance(element)).toBeInstanceOf(DummyClass)
|
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', () => {
|
it('should return null when there is no instance', () => {
|
||||||
fixtureEl.innerHTML = '<div></div>'
|
fixtureEl.innerHTML = '<div></div>'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user