Skip to content

Commit

Permalink
Merge pull request #1297 from capricorn86/1218-regression-typeerror-c…
Browse files Browse the repository at this point in the history
…annot-set-property-loading-of-object-object-which-has-only-a-getter

fix: [#1218] Adds missing setter for the HTMLImageElement.loading pro…
  • Loading branch information
capricorn86 committed Mar 11, 2024
2 parents 54d1ae0 + e667b6a commit f6e8467
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@ export default class HTMLImageElement extends HTMLElement implements IHTMLImageE
* @returns Loading.
*/
public get loading(): string {
return this[PropertySymbol.loading];
const loading = this.getAttribute('loading');
return loading === 'eager' || loading === 'lazy' ? loading : 'auto';
}

/**
* Sets loading.
*
* @param loading Loading.
*/
public set loading(loading: string) {
this.setAttribute('loading', loading);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,36 @@ describe('HTMLImageElement', () => {
});

describe('get loading()', () => {
it('Returns "auto".', () => {
it('Returns "auto" by default.', () => {
const element = <HTMLImageElement>document.createElement('img');
expect(element.loading).toBe('auto');
});

it('Returns "eager" if the attribute is set to "eager".', () => {
const element = <HTMLImageElement>document.createElement('img');
element.setAttribute('loading', 'eager');
expect(element.loading).toBe('eager');
});

it('Returns "lazy" if the attribute is set to "lazy".', () => {
const element = <HTMLImageElement>document.createElement('img');
element.setAttribute('loading', 'lazy');
expect(element.loading).toBe('lazy');
});

it('Returns "auto" if value is invalid.', () => {
const element = <HTMLImageElement>document.createElement('img');
element.setAttribute('loading', 'invalid');
expect(element.loading).toBe('auto');
});
});

describe('set loading()', () => {
it('Sets the "loading" attribute.', () => {
const element = <HTMLImageElement>document.createElement('img');
element.loading = 'anyValueIsAllowed';
expect(element.getAttribute('loading')).toBe('anyValueIsAllowed');
});
});

describe('get x()', () => {
Expand Down

0 comments on commit f6e8467

Please sign in to comment.