Skip to content

Commit 484640b

Browse files
fix calling Api constructor with wrong parameter
1 parent 33d969a commit 484640b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/useDynamicTabs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import useDynTabs from './useDynamicTabs.js';
77
import { ApiContext, StateContext, ForceUpdateContext } from "../utils/context.js";
88
const getDeps = function () {
99
const getApiInstance = (options) => {
10-
return new (Api)(options);
10+
return new (Api)({ options });
1111
};
1212
return { reducer, getApiInstance, PanelList, TabList, ApiContext, StateContext, ForceUpdateContext };
1313
};

src/utils/api/api.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import API from './api.js';
2-
let obj = '';
32
beforeEach(() => {
4-
obj = new (API)();
3+
54
});
65
describe('user api : ', () => {
76
test('list all available props for consumer', () => {
7+
const obj = new (API)({ a: 2 });
88
const userApi = ['getTab', 'setTab', 'off', 'on', 'one', 'getOption', 'setOption', 'getCopyPerviousData', 'getCopyData',
99
'isSelected', 'isOpen', 'select', 'open', 'close', 'refresh'];
1010
expect(Object.keys(obj.userProxy).length === userApi.length).toBe(true);
@@ -16,6 +16,12 @@ describe('user api : ', () => {
1616
});
1717
expect(_isEqual).toBe(true);
1818
});
19+
test('calling Api constructor with option parameter correctly', () => {
20+
const obj1 = new (API)(), obj2 = new (API)({ mockProp: 1 }), obj3 = new (API)({ options: { mockProp: 1 } });
21+
expect(obj1.helper != undefined).toBe(true);
22+
expect(!obj2.getOption('mockProp') == true).toBe(true);
23+
expect(obj3.getOption('mockProp') === 1).toBe(true);
24+
});
1925
});
2026

2127

0 commit comments

Comments
 (0)