Open builtbybrayne opened 4 years ago
Getting the same error on our Test-Pipeline. We are required to sync our time with the backend, so we mock the time on Server-Side:
<% if Rails.env.test? && defined?(Timecop) && Timecop.top_stack_item %>
<%= javascript_include_tag "mockdate/lib/mockdate" %>
<%= javascript_tag "set('#{Time.now}')" %>
<% end %>
On a simple new Date()
call in frontend, we are facing the same error :
severe
http://application:3333/assets/mockdate/lib/mockdate-718c595589fef86d66b941965fcaf05ed4a00f53815587930cc75d790fdf9156.js 14:22
application_1 | Uncaught ReferenceError: exports is not defined application_1 | Uncaught TypeError: Date is not a constructor
@builtbybrayne Sorry for such a long delay 😦
I'm wondering if the fix here is to do globalThis.Date = MockDate
. Is that essentially what you did to get this working on your end?
@Frozen-byte Your issue might be due to the fact that I accidentally broke the browser build in version 3.x. Please try version 3.0.3, it should be fixed.
I'm wondering if the fix here is to do
globalThis.Date = MockDate
. Is that essentially what you did to get this working on your end?
I know I'd like to be able to try this at overwriting the global Date in Node, so I imagine such an export would work great.
v3.0.2
I got
ReferenceError: Date is not defined
when callingreset()
.My tests are Babel-compiled on the fly, and I believe this breaks the link between the
Date
reference and the actualglobal.Date
class.I have a fix, and would offer a PR but I'm not familiar with typescript.
I did copy your earlier js version (27a1a733709da04d9463fa53c9454ff7c3885e17 - Remove Dead Code) and replaced all
Date
references withglobal.Date
. This works fine.(Also, by the way, when you merged your ts branch, you accidentally undid the removal of the dead code in the mentioned commit).