Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added functionality to avoid rendering responsive plugin when placeholder is added #221

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: confirm we avoid rendering responsive plugin when placeholder i…
…s added
  • Loading branch information
cloudy408 committed Sep 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1844fc23e5abb17befe578adb07e3e620b097de6
24 changes: 24 additions & 0 deletions packages/html/__tests__/HtmlImageLayer.test.ts
Original file line number Diff line number Diff line change
@@ -127,4 +127,28 @@ describe('HtmlImageLayer tests', function () {
// test that the src which set by HtmlImageLayer contains last character "B" which is the character of placeholder plugin
expect(imgSetAttributeSpy.mock.calls[0][1]).toEqualAnalyticsToken('BAXAABABB');
});

it.only('should verfiy no responsive image request is fired with placeholder plugin', async function () {
const OriginalImage = Image;
// mocking Image constructor in order to simulate firing 'load' event
jest.spyOn(global, "Image").mockImplementation(() => {
const img = new OriginalImage();
setTimeout(() => {
img.dispatchEvent(new Event("load"));
}, 10)
return img;

})
const parentElement = document.createElement('div');
const img = document.createElement('img');
parentElement.append(img);
const imgSrcSpy = jest.spyOn(img, 'src', 'set');
const imgSetAttributeSpy = jest.spyOn(img, 'setAttribute');
new HtmlImageLayer(img, cldImage, [responsive({steps: 200}),placeholder()], sdkAnalyticsTokens);
await flushPromises();
expect(imgSrcSpy).toHaveBeenCalledTimes(1);
// test that the initial src is set to a token contains last character "B" which is the character of placeholder plugin
const imgSrcSpyAnalyticsToken = imgSrcSpy.mock.calls[0][0];
expect(imgSrcSpyAnalyticsToken).toEqualAnalyticsToken('BAXAABABB');
});
});