{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/jest/issues/3341","repository_url":"https://api.github.com/repos/facebook/jest","labels_url":"https://api.github.com/repos/facebook/jest/issues/3341/labels{/name}","comments_url":"https://api.github.com/repos/facebook/jest/issues/3341/comments","events_url":"https://api.github.com/repos/facebook/jest/issues/3341/events","html_url":"https://github.com/facebook/jest/issues/3341","id":223313361,"number":3341,"title":"Mocking Date.now() doesn't work on CircleCI","user":{"login":"chrishiste","id":24848602,"avatar_url":"https://avatars1.githubusercontent.com/u/24848602?v=3","gravatar_id":"","url":"https://api.github.com/users/chrishiste","html_url":"https://github.com/chrishiste","followers_url":"https://api.github.com/users/chrishiste/followers","following_url":"https://api.github.com/users/chrishiste/following{/other_user}","gists_url":"https://api.github.com/users/chrishiste/gists{/gist_id}","starred_url":"https://api.github.com/users/chrishiste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrishiste/subscriptions","organizations_url":"https://api.github.com/users/chrishiste/orgs","repos_url":"https://api.github.com/users/chrishiste/repos","events_url":"https://api.github.com/users/chrishiste/events{/privacy}","received_events_url":"https://api.github.com/users/chrishiste/received_events","type":"User","site_admin":false},"labels":[{"id":442782992,"url":"https://api.github.com/repos/facebook/jest/labels/Needs%20more%20info","name":"Needs more info","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-21T08:25:33Z","updated_at":"2017-04-24T02:58:31Z","closed_at":null,"body":"Hello Jesters,\r\n\r\nI'm having a problem on CircleCI while running my tests. I'm mocking \"Date.now\" to have the same date all the time from moment.js. It works perfectly on my local machine but the test fail on CircleCI. I'm mocking Date.now because my code is highly time dependant. Every test passes expect the ones using moment.js. \r\n\r\nThis is the code I use (Flow says it's alright) :\r\n```js\r\nglobal.Date.now = jest.fn(() => 1490760656000);\r\n```\r\nI also tried using timekeeper : https://github.com/vesln/timekeeper\r\n\r\nI thought of mocking moment but it seems like a lot of work and it will make my tests and data mocks really complicated to understand.\r\n\r\nI saw we can set a timezone in the CircleCI config but it's not enough has I want a specific date during the execution of the tests. Maybe there is a way but I couldn't find it unfortunately.\r\n\r\nI also looked for Jest fake timer system but it's only for timers not dates.\r\n\r\nI use the latest version of Jest and run CircleCI on Node 6.10.\r\nI run the test with \"--runInBand\".\r\n\r\nAny idea about this ? \r\n"},"comment":{"url":"https://api.github.com/repos/facebook/jest/issues/comments/296513698","html_url":"https://github.com/facebook/jest/issues/3341#issuecomment-296513698","issue_url":"https://api.github.com/repos/facebook/jest/issues/3341","id":296513698,"user":{"login":"thymikee","id":5106466,"avatar_url":"https://avatars1.githubusercontent.com/u/5106466?v=3","gravatar_id":"","url":"https://api.github.com/users/thymikee","html_url":"https://github.com/thymikee","followers_url":"https://api.github.com/users/thymikee/followers","following_url":"https://api.github.com/users/thymikee/following{/other_user}","gists_url":"https://api.github.com/users/thymikee/gists{/gist_id}","starred_url":"https://api.github.com/users/thymikee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thymikee/subscriptions","organizations_url":"https://api.github.com/users/thymikee/orgs","repos_url":"https://api.github.com/users/thymikee/repos","events_url":"https://api.github.com/users/thymikee/events{/privacy}","received_events_url":"https://api.github.com/users/thymikee/received_events","type":"User","site_admin":false},"created_at":"2017-04-24T02:58:31Z","updated_at":"2017-04-24T02:58:31Z","body":"If you have some time, could you please setup a repo with a simple test case like this:\r\n```js\r\ntest('date', () => {\r\n  Date.now = jest.fn(() => 1490760656000);\r\n  const date1 = Date.now();\r\n  const date2 = Date.now();\r\n  expect(Date.now).toHaveBeenCalled();\r\n  expect(date1).toEqual(date2);\r\n});\r\n```\r\nand add Circle and Travis running this code on different Node versions? "}}
{"actor":{"display_login":"thymikee"}}