Skip to content

Commit a3ffb11

Browse files
committed
add tests for realtime updates
1 parent a376de1 commit a3ffb11

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/relative-time.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ suite('relative-time', function () {
5858
assert.equal(counter, 1)
5959
})
6060

61+
test('updates the time automatically when it is a few seconds ago', async function () {
62+
this.timeout(3000)
63+
const el = document.createElement('relative-time')
64+
el.setAttribute('datetime', new Date(Date.now() + 25000).toISOString())
65+
const display = el.shadowRoot?.textContent || el.textContent
66+
assert.match(display, /in \d+ seconds/)
67+
await new Promise(resolve => setTimeout(resolve, 2000))
68+
const nextDisplay = el.shadowRoot.textContent || el.textContent
69+
assert.match(nextDisplay, /in \d+ seconds/)
70+
console.log(nextDisplay, display)
71+
assert.notEqual(nextDisplay, display)
72+
})
73+
6174
test("doesn't error when no date is provided", function () {
6275
const element = document.createElement('relative-time')
6376
assert.doesNotThrow(() => element.attributeChangedCallback('datetime', null, null))

0 commit comments

Comments
 (0)