Skip to content

Commit

Permalink
fix(partytown): add style to image class (#239)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksander Kuźma <aleksander.a.kuzma@gmail.com>
  • Loading branch information
adamdbradley and akselander committed Aug 29, 2022
1 parent aa561c0 commit aff8eef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/web-worker/worker-image.ts
Expand Up @@ -9,11 +9,13 @@ export const createImageConstructor = (env: WebWorkerEnvironment) =>
s: string;
l: EventHandler[];
e: EventHandler[];
style: Record<string, string>;

constructor() {
this.s = '';
this.l = [];
this.e = [];
this.style = {};
}

get src() {
Expand Down
4 changes: 4 additions & 0 deletions tests/platform/image/image.spec.ts
Expand Up @@ -35,6 +35,10 @@ test('image', async ({ page }) => {
const testImgListenerError = page.locator('#testImgListenerError');
await expect(testImgListenerError).toHaveText('error');

await page.waitForSelector('.testImgStyle');
const testImgStyle = page.locator('#testImgStyle');
await expect(testImgStyle).toHaveText('red');

await page.waitForSelector('.testImgSrc');
const testImgSrc = page.locator('#testImgSrc');
await expect(testImgSrc).toHaveText('dot.gif?imageSrcTest');
Expand Down
17 changes: 17 additions & 0 deletions tests/platform/image/index.html
Expand Up @@ -184,6 +184,23 @@ <h1>Image</h1>
</script>
</li>

<li>
<strong>&lt;img&gt; style</strong>
<code id="testImgStyle"></code>
<script type="text/partytown">
(function () {
const image = new Image();
image.style.color = 'red'
image.addEventListener('error', function (ev) {
const elm = document.getElementById('testImgStyle');
elm.textContent = image.style.color;
elm.className = 'testImgStyle';
});
image.src = '404.gif?testImgStyle';
})();
</script>
</li>

<li>
<strong>&lt;img&gt; src</strong>
<code id="testImgSrc"></code>
Expand Down

1 comment on commit aff8eef

@vercel
Copy link

@vercel vercel bot commented on aff8eef Aug 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.