mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-08 22:56:46 +02:00
Add getOrCreateInstance
method in base-component (#33276)
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com> Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -164,4 +164,26 @@ describe('Button', () => {
|
||||
expect(Button.getInstance(div)).toEqual(null)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getOrCreateInstance', () => {
|
||||
it('should return button instance', () => {
|
||||
fixtureEl.innerHTML = '<div></div>'
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const button = new Button(div)
|
||||
|
||||
expect(Button.getOrCreateInstance(div)).toEqual(button)
|
||||
expect(Button.getInstance(div)).toEqual(Button.getOrCreateInstance(div, {}))
|
||||
expect(Button.getOrCreateInstance(div)).toBeInstanceOf(Button)
|
||||
})
|
||||
|
||||
it('should return new instance when there is no button instance', () => {
|
||||
fixtureEl.innerHTML = '<div></div>'
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
expect(Button.getInstance(div)).toEqual(null)
|
||||
expect(Button.getOrCreateInstance(div)).toBeInstanceOf(Button)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user