mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-22 15:39:59 +00: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 getInstance(element) {
|
||||
return Data.get(element, this.DATA_KEY)
|
||||
return Data.get(getElement(element), this.DATA_KEY)
|
||||
}
|
||||
|
||||
static getOrCreateInstance(element, config = {}) {
|
||||
|
@ -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>'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user