diff --git a/packages/happy-dom/src/nodes/html-image-element/HTMLImageElement.ts b/packages/happy-dom/src/nodes/html-image-element/HTMLImageElement.ts
index daffead4b..22fd304e9 100644
--- a/packages/happy-dom/src/nodes/html-image-element/HTMLImageElement.ts
+++ b/packages/happy-dom/src/nodes/html-image-element/HTMLImageElement.ts
@@ -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);
}
/**
diff --git a/packages/happy-dom/test/nodes/html-image-element/HTMLImageElement.test.ts b/packages/happy-dom/test/nodes/html-image-element/HTMLImageElement.test.ts
index f01c9d737..bbdfdb483 100644
--- a/packages/happy-dom/test/nodes/html-image-element/HTMLImageElement.test.ts
+++ b/packages/happy-dom/test/nodes/html-image-element/HTMLImageElement.test.ts
@@ -109,10 +109,36 @@ describe('HTMLImageElement', () => {
});
describe('get loading()', () => {
- it('Returns "auto".', () => {
+ it('Returns "auto" by default.', () => {
const element = document.createElement('img');
expect(element.loading).toBe('auto');
});
+
+ it('Returns "eager" if the attribute is set to "eager".', () => {
+ const element = document.createElement('img');
+ element.setAttribute('loading', 'eager');
+ expect(element.loading).toBe('eager');
+ });
+
+ it('Returns "lazy" if the attribute is set to "lazy".', () => {
+ const element = document.createElement('img');
+ element.setAttribute('loading', 'lazy');
+ expect(element.loading).toBe('lazy');
+ });
+
+ it('Returns "auto" if value is invalid.', () => {
+ const element = document.createElement('img');
+ element.setAttribute('loading', 'invalid');
+ expect(element.loading).toBe('auto');
+ });
+ });
+
+ describe('set loading()', () => {
+ it('Sets the "loading" attribute.', () => {
+ const element = document.createElement('img');
+ element.loading = 'anyValueIsAllowed';
+ expect(element.getAttribute('loading')).toBe('anyValueIsAllowed');
+ });
});
describe('get x()', () => {