{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/jest/issues/2234","repository_url":"https://api.github.com/repos/facebook/jest","labels_url":"https://api.github.com/repos/facebook/jest/issues/2234/labels{/name}","comments_url":"https://api.github.com/repos/facebook/jest/issues/2234/comments","events_url":"https://api.github.com/repos/facebook/jest/issues/2234/events","html_url":"https://github.com/facebook/jest/issues/2234","id":193880542,"node_id":"MDU6SXNzdWUxOTM4ODA1NDI=","number":2234,"title":"Mocking current time for Date","user":{"login":"calebmer","id":8282507,"node_id":"MDQ6VXNlcjgyODI1MDc=","avatar_url":"https://avatars1.githubusercontent.com/u/8282507?v=4","gravatar_id":"","url":"https://api.github.com/users/calebmer","html_url":"https://github.com/calebmer","followers_url":"https://api.github.com/users/calebmer/followers","following_url":"https://api.github.com/users/calebmer/following{/other_user}","gists_url":"https://api.github.com/users/calebmer/gists{/gist_id}","starred_url":"https://api.github.com/users/calebmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calebmer/subscriptions","organizations_url":"https://api.github.com/users/calebmer/orgs","repos_url":"https://api.github.com/users/calebmer/repos","events_url":"https://api.github.com/users/calebmer/events{/privacy}","received_events_url":"https://api.github.com/users/calebmer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":33,"created_at":"2016-12-06T20:51:58Z","updated_at":"2018-10-11T14:11:45Z","closed_at":"2016-12-06T20:56:16Z","author_association":"CONTRIBUTOR","body":"Is there a way to mock the current date? So that `new Date()` or `Date.now()` returns a mocked time instead of the current time?"},"comment":{"url":"https://api.github.com/repos/facebook/jest/issues/comments/428970593","html_url":"https://github.com/facebook/jest/issues/2234#issuecomment-428970593","issue_url":"https://api.github.com/repos/facebook/jest/issues/2234","id":428970593,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODk3MDU5Mw==","user":{"login":"masungwon","id":17363774,"node_id":"MDQ6VXNlcjE3MzYzNzc0","avatar_url":"https://avatars0.githubusercontent.com/u/17363774?v=4","gravatar_id":"","url":"https://api.github.com/users/masungwon","html_url":"https://github.com/masungwon","followers_url":"https://api.github.com/users/masungwon/followers","following_url":"https://api.github.com/users/masungwon/following{/other_user}","gists_url":"https://api.github.com/users/masungwon/gists{/gist_id}","starred_url":"https://api.github.com/users/masungwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masungwon/subscriptions","organizations_url":"https://api.github.com/users/masungwon/orgs","repos_url":"https://api.github.com/users/masungwon/repos","events_url":"https://api.github.com/users/masungwon/events{/privacy}","received_events_url":"https://api.github.com/users/masungwon/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T14:11:45Z","updated_at":"2018-10-11T14:11:45Z","author_association":"NONE","body":"I needed to mock `new Date()` but needed the rest of `Date` functionalities to work as normal. This is the solution that worked for me.\r\n```\r\ndescribe('...', () => {\r\n  const RealDate = Date;\r\n\r\n  function mockDate(isoDate) {\r\n    global.Date = class extends RealDate {\r\n      constructor(...args) {\r\n        if (args.length) return new RealDate(...args);\r\n        return new RealDate(isoDate);\r\n      }\r\n    };\r\n  }\r\n\r\n  afterEach(() => {\r\n    global.Date = RealDate;\r\n  });\r\n\r\n  it('...', () => {\r\n    mockDate('2018-01-01');\r\n    // rest of the code\r\n  });\r\n})\r\n```"}}
{"actor":{"display_login":"masungwon"}}