Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeStamp property missing from Event & CustomEvent #722

Closed
aripalo opened this issue Feb 7, 2023 · 0 comments · Fixed by #723
Closed

timeStamp property missing from Event & CustomEvent #722

aripalo opened this issue Feb 7, 2023 · 0 comments · Fixed by #723
Labels
enhancement New feature or request

Comments

@aripalo
Copy link
Contributor

aripalo commented Feb 7, 2023

Is your feature request related to a problem? Please describe.

Event (and hence CustomEvent) are missing the timeStamp property. This means that for example unit tests running with happy-dom will fail if they try to access the undefined timeStamp property.

Example code:

console.debug("TYPEOF timeStamp", typeof event.timeStamp);
TYPEOF timeStamp undefined

Describe the solution you'd like
Happy DOM should assign the timeStamp property.

(I will be providing a pull request.) I've provided a Pull Request for this at #723

Describe alternatives you've considered

  • Hack my own tests to check if timeStamp is undefined – basically making the tests useless
  • Override the global CustomEventfeels dirty

Additional context

Looking at jsdom implementation of timeStamp is just a Date.now() – which does not match the specification (see MDN and Spec):

This value is the number of milliseconds elapsed from the beginning of the time origin until the event was created. If the global object is Window, the time origin is the moment the user clicked on the link, or the script that initiated the loading of the document. In a worker, the time origin is the moment of creation of the worker.

I think we could do better: My proposed solution is to use performance.timeOrigin as the time origin to resolve the relative Event timeStamp value.

@aripalo aripalo added the enhancement New feature or request label Feb 7, 2023
aripalo added a commit to aripalo/happy-dom that referenced this issue Feb 7, 2023
aripalo added a commit to aripalo/happy-dom that referenced this issue Feb 9, 2023
Co-authored-by: David Ortner <david@ortner.se>
aripalo added a commit to aripalo/happy-dom that referenced this issue Feb 9, 2023
Co-authored-by: David Ortner <david@ortner.se>
aripalo added a commit to aripalo/happy-dom that referenced this issue Feb 9, 2023
capricorn86 pushed a commit to aripalo/happy-dom that referenced this issue Feb 13, 2023
capricorn86 pushed a commit to aripalo/happy-dom that referenced this issue Feb 13, 2023
capricorn86 added a commit that referenced this issue Feb 13, 2023
…ing-from-event

#722@minor: Add timeStamp property to Event.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant