Skip to content

Commit

Permalink
add tests for realtime updates
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Nov 7, 2022
1 parent a376de1 commit a3ffb11
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/relative-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ suite('relative-time', function () {
assert.equal(counter, 1)
})

test('updates the time automatically when it is a few seconds ago', async function () {
this.timeout(3000)
const el = document.createElement('relative-time')
el.setAttribute('datetime', new Date(Date.now() + 25000).toISOString())
const display = el.shadowRoot?.textContent || el.textContent
assert.match(display, /in \d+ seconds/)
await new Promise(resolve => setTimeout(resolve, 2000))
const nextDisplay = el.shadowRoot.textContent || el.textContent
assert.match(nextDisplay, /in \d+ seconds/)
console.log(nextDisplay, display)
assert.notEqual(nextDisplay, display)
})

test("doesn't error when no date is provided", function () {
const element = document.createElement('relative-time')
assert.doesNotThrow(() => element.attributeChangedCallback('datetime', null, null))
Expand Down

0 comments on commit a3ffb11

Please sign in to comment.