Skip to content

Commit

Permalink
test: added test for percyScreenshot. fix: change response.data -> re…
Browse files Browse the repository at this point in the history
…sponse.body.data
  • Loading branch information
this-is-shivamsingh committed Jan 29, 2024
1 parent 8518d03 commit 0b839b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = async function percySnapshot(driver, name, options) {
name,
url
});
return response.data;
return response?.body?.data;
} catch (error) {
// Handle errors
log.error(`Could not take DOM snapshot "${name}"`);
Expand Down Expand Up @@ -108,7 +108,7 @@ module.exports.percyScreenshot = async function percyScreenshot(driver, name, op
snapshotName: name,
options
});
return response.data;
return response?.body?.data;
} catch (error) {
// Handle errors
log.error(`Could not take Screenshot "${name}"`);
Expand Down
18 changes: 12 additions & 6 deletions test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ describe('percyScreenshot', () => {
const considerElement = { getId: () => {} };
const mockElement = spyOn(element, 'getId').and.callFake(() => { return new Promise((resolve, _) => resolve('123')); });
const mockConsiderElement = spyOn(considerElement, 'getId').and.callFake(() => { return new Promise((resolve, _) => resolve('456')); });
const mockresponse = {
success: 'true',
data: 'sync_data'
}
const mockedPostCall = spyOn(percySnapshot, 'request').and.callFake(() => mockresponse);
const response = await percyScreenshot(driver, 'Snapshot 2', { ignoreRegionSeleniumElements: [element], considerRegionSeleniumElements: [considerElement] });
await percyScreenshot(driver, 'Snapshot 2', { ignoreRegionSeleniumElements: [element], considerRegionSeleniumElements: [considerElement] });

expect(mockElement).toHaveBeenCalled();
expect(mockConsiderElement).toHaveBeenCalled();
Expand All @@ -158,7 +154,17 @@ describe('percyScreenshot', () => {
consider_region_selenium_elements: ['456']
}
}));
expect(response).toEqual(mockresponse.data);
});

it('receive data object from CLI response', async() => {
const mockResponse = {
success: true,
body: { data: { some_data: 'some_data ' } }
}

spyOn(percySnapshot, 'request').and.callFake(() => mockResponse);
const response = await percyScreenshot(driver, 'Snapshot 1');
expect(response).toEqual(mockResponse.body.data);
});

it('posts driver details to the local percy server with ignore and consider region and sync', async () => {
Expand Down

0 comments on commit 0b839b8

Please sign in to comment.