Skip to content

Commit

Permalink
fix: [#1218] Adds missing setter for the HTMLImageElement.loading pro…
Browse files Browse the repository at this point in the history
…perty
  • Loading branch information
capricorn86 committed Mar 11, 2024
1 parent 54d1ae0 commit e667b6a
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 e667b6a

Please sign in to comment.