diff options
author | GeoSot <geo.sotis@gmail.com> | 2021-06-03 18:53:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 18:53:27 +0300 |
commit | c98657b8303150bfda3bdea750055b83a29b27a3 (patch) | |
tree | 6f7b347461e3fdd380f0d4e990440e6fc427af61 /js/tests/unit/tab.spec.js | |
parent | 4a5029ea29ac75243dfec68153051292fc70f5cf (diff) |
Add `getOrCreateInstance` method in base-component (#33276)
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Diffstat (limited to 'js/tests/unit/tab.spec.js')
-rw-r--r-- | js/tests/unit/tab.spec.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index 76d4765258..621012c12e 100644 --- a/js/tests/unit/tab.spec.js +++ b/js/tests/unit/tab.spec.js @@ -433,6 +433,28 @@ describe('Tab', () => { }) }) + describe('getOrCreateInstance', () => { + it('should return tab instance', () => { + fixtureEl.innerHTML = '<div></div>' + + const div = fixtureEl.querySelector('div') + const tab = new Tab(div) + + expect(Tab.getOrCreateInstance(div)).toEqual(tab) + expect(Tab.getInstance(div)).toEqual(Tab.getOrCreateInstance(div, {})) + expect(Tab.getOrCreateInstance(div)).toBeInstanceOf(Tab) + }) + + it('should return new instance when there is no tab instance', () => { + fixtureEl.innerHTML = '<div></div>' + + const div = fixtureEl.querySelector('div') + + expect(Tab.getInstance(div)).toEqual(null) + expect(Tab.getOrCreateInstance(div)).toBeInstanceOf(Tab) + }) + }) + describe('data-api', () => { it('should create dynamically a tab', done => { fixtureEl.innerHTML = [ |