Skip to content

Commit

Permalink
fix:unit test case
Browse files Browse the repository at this point in the history
Signed-off-by: Amitkanswal <[email protected]>
  • Loading branch information
Amitkanswal committed Oct 21, 2024
1 parent 4e74e54 commit ecf2d02
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions __test__/uiLocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ describe("UI Location", () => {

beforeEach(() => {
mockPostRobot = postRobot;
opts = { method: 'GET', url: '/test' };
opts = { method: 'GET', url: '/test', baseURL: 'https://test.com' };
uiLocationInstance = new UiLocation(initData);
onError = jest.fn();
uiLocationInstance.api = jest.fn().mockResolvedValue({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
body: {}
});
});
Expand All @@ -158,18 +159,21 @@ describe("UI Location", () => {
const result = await uiLocationInstance.api({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
body: {}
});

// Assertions
expect(uiLocationInstance.api).toHaveBeenCalledWith({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
body: {}
});
expect(result).toEqual({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
body: {}
});

Expand All @@ -190,6 +194,7 @@ describe("UI Location", () => {
await expect(uiLocationInstance.api({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
body: {}
})).rejects.toThrow('Test error');
});
Expand All @@ -203,12 +208,13 @@ describe("UI Location", () => {
let onError: jest.Mock;
beforeEach(() => {
mockPostRobot = postRobot;
opts = { method: 'GET', url: '/test' };
opts = { method: 'GET', url: '/test', baseURL: 'https://test.com' };
uiLocationInstance = new UiLocation(initData);
onError = jest.fn();
uiLocationInstance.createAdapter = jest.fn().mockResolvedValue({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});
});
Expand All @@ -228,18 +234,21 @@ describe("UI Location", () => {
const result = await uiLocationInstance.createAdapter({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});

// Assertions
expect(uiLocationInstance.createAdapter).toHaveBeenCalledWith({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});
expect(result).toEqual({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
});
})
Expand All @@ -259,6 +268,7 @@ describe("UI Location", () => {
await expect(uiLocationInstance.createAdapter({
method: 'GET',
url: '/test?limit=10&skip=0',
baseURL: 'https://test.com',
data: {}
})).rejects.toThrow('Test error');
})
Expand Down

0 comments on commit ecf2d02

Please sign in to comment.