question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

timeStamp in event created by `createEvent` is not used

See original GitHub issue
  • @testing-library/react version: 11.2.0
  • Testing Framework and version: jest-26.0.15
  • DOM Environment: jsdom-16.4.0

Relevant code or config:

import { createEvent } from '@testing-library/react'

test('event uses timeStamp', () => {
  const mockEvent = createEvent.click(document.body, { timeStamp: 1000000 })
  expect(mockEvent.timeStamp).toBe(1000000)
})

What you did:

  • used createEvent to create an event with a manipulated timeStamp

What happened:

  • the created event had a native timeStamp

Reproduction:

See test case above

Problem description:

Overwriting timeStamp is one of the documented use cases for createEvent, see https://testing-library.com/docs/dom-testing-library/api-events/#createeventeventname

Suggested solution:

As a workaround, one can use Object.defineProperty(event, ‘timeStamp’, { value: 1000000 });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
drorhellercommented, May 5, 2021

Hi, I’d like to update the doc on this

1reaction
eps1loncommented, Dec 3, 2020

Thanks for the report.

Can you set this property with the native event API? I think browsers set this automatically i.e. you’re not supposed to be able to manipulate them with conventional APIs (https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp).

Though Object.defineProperty works. I’m leaning towards following the DOM API here. I think it should be obvious from your test if you’re mocking something.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL Incorrect AT value using current_timestamp with event ...
CREATE EVENT event_name ON SCHEDULE AT CURRENT_TIMESTAMP + 30 DO UPDATE test_table SET value = 0 WHERE id = 1;. It sometimes works...
Read more >
create event(V4) data error - Power Platform Community
I'm trying to create a calendar for Outlook "create event(V4)". Triggered data is Dataverse. I have set "DateOnly" data type for my date....
Read more >
13.1.12 CREATE EVENT Statement - MySQL :: Developer Zone
13.1.12 CREATE EVENT Statement · AT timestamp is used for a one-time event. · To repeat actions at a regular interval, use an...
Read more >
Event.timeStamp - Web APIs | MDN
The timeStamp read-only property of the Event interface returns the time (in milliseconds) at which the event was created.
Read more >
Class Calendar | Apps Script - Google Developers
createEvent (title, startTime, endTime, options), CalendarEvent ... date, Date, the date of the event (only the day is used; the time is ignored) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found