forked from capricorn86/happy-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [capricorn86#1431] Implement HTMLTimeElement
- Loading branch information
Showing
6 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/happy-dom/src/nodes/html-time-element/HTMLTimeElement.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import HTMLElement from '../html-element/HTMLElement.js'; | ||
|
||
/** | ||
* HTML Time Element. | ||
* | ||
* Reference: | ||
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement | ||
*/ | ||
export default class HTMLTimeElement extends HTMLElement { | ||
/** | ||
* Returns dateTime. | ||
* | ||
* @returns dateTime. | ||
*/ | ||
public get dateTime(): string { | ||
return this.getAttribute('dateTime') || ''; | ||
} | ||
|
||
/** | ||
* Sets dateTime. | ||
* | ||
* @param dateTime dateTime. | ||
*/ | ||
public set dateTime(dateTime: string) { | ||
this.setAttribute('dateTime', dateTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/happy-dom/test/nodes/html-time-element/HTMLTimeElement.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
import Document from '../../../src/nodes/document/Document.js'; | ||
import HTMLTimeElement from '../../../src/nodes/html-time-element/HTMLTimeElement.js'; | ||
import Window from '../../../src/window/Window.js'; | ||
|
||
describe('HTMLTimeElement', () => { | ||
let window: Window; | ||
let document: Document; | ||
let element: HTMLTimeElement; | ||
|
||
beforeEach(() => { | ||
window = new Window(); | ||
document = window.document; | ||
element = <HTMLTimeElement>document.createElement('time'); | ||
}); | ||
|
||
describe('get dateTime()', () => { | ||
it('Gets the attribute value "datetime".', () => { | ||
element.setAttribute('datetime', '1969-07-20'); | ||
expect(element.dateTime).toBe('1969-07-20'); | ||
}); | ||
|
||
it('Returns "" if the "datetime" attribute is not set.', () => { | ||
expect(element.dateTime).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('set dateTime()', () => { | ||
it('Sets the attribute value "datetime".', () => { | ||
element.dateTime = '1969-07-20'; | ||
expect(element.getAttribute('datetime')).toBe('1969-07-20'); | ||
}); | ||
}); | ||
}); |