Skip to content

Commit af8eb89

Browse files
fix setOption function bug and wirte a test for it.
it should return the context.
1 parent 8b18027 commit af8eb89

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/utils/api/api.factory.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ const _apiProps = {
7575
return this.optionsManager.getOption(name);
7676
},
7777
setOption: function (name, value) {
78-
return this.optionsManager.setOption(name, value);
78+
this.optionsManager.setOption(name, value);
79+
return this;
7980
},
8081
getPreviousData: function () {
8182
return this.helper.getCopyState(this.previousState);

src/utils/api/api.factory.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,23 @@ describe('Api.prototype.setTab : ', () => {
478478
obj.optionsManager.validatePanelComponent,
479479
);
480480
});
481+
test('it should return the context', () => {
482+
obj.optionsManager.validateObjectiveTabData = jest.fn(() => obj.optionsManager);
483+
obj.optionsManager.validatePanelComponent = jest.fn(() => obj.optionsManager);
484+
const result = obj.setTab('1', {title: 'c'});
485+
expect(result).toEqual(obj);
486+
});
487+
});
488+
describe('Api.prototype.setOption : ', () => {
489+
test('it should call optionsManager.setOption internally', () => {
490+
obj.optionsManager.setOption = jest.fn(() => obj.optionsManager);
491+
obj.setOption('isVertical', true);
492+
expect(obj.optionsManager.setOption.mock.calls.length).toBe(1);
493+
});
494+
test('it should return the context', () => {
495+
const result = obj.setOption('isVertical', true);
496+
expect(result).toEqual(obj);
497+
});
481498
});
482499
describe('Api.prototype._subscribeSelectedTabsHistory : ', () => {
483500
test('it should call "on" method', () => {

0 commit comments

Comments
 (0)