{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/jest/issues/3211","repository_url":"https://api.github.com/repos/facebook/jest","labels_url":"https://api.github.com/repos/facebook/jest/issues/3211/labels{/name}","comments_url":"https://api.github.com/repos/facebook/jest/issues/3211/comments","events_url":"https://api.github.com/repos/facebook/jest/issues/3211/events","html_url":"https://github.com/facebook/jest/issues/3211","id":217044764,"number":3211,"title":"setTimeout not triggering when unit testing","user":{"login":"Shooshte","id":11058850,"avatar_url":"https://avatars1.githubusercontent.com/u/11058850?v=4","gravatar_id":"","url":"https://api.github.com/users/Shooshte","html_url":"https://github.com/Shooshte","followers_url":"https://api.github.com/users/Shooshte/followers","following_url":"https://api.github.com/users/Shooshte/following{/other_user}","gists_url":"https://api.github.com/users/Shooshte/gists{/gist_id}","starred_url":"https://api.github.com/users/Shooshte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shooshte/subscriptions","organizations_url":"https://api.github.com/users/Shooshte/orgs","repos_url":"https://api.github.com/users/Shooshte/repos","events_url":"https://api.github.com/users/Shooshte/events{/privacy}","received_events_url":"https://api.github.com/users/Shooshte/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-03-26T11:22:09Z","updated_at":"2017-12-14T10:30:21Z","closed_at":"2017-03-26T11:40:20Z","author_association":"NONE","body":"```\r\n  it('mock setTimeout test', () => {    \r\n    setTimeout(() => {\r\n      console.log('TIME IS UP');\r\n    }, 1000);\r\n  });\r\n```\r\n\r\nWhy is there no message in the console? I also tried using done() after the console.log statement, but the results are the same.\r\n\r\nMy jest config:\r\n```\r\n  \"jest\": {\r\n    \"collectCoverageFrom\": [\r\n      \"src/**/*.{js,jsx}\"\r\n    ],\r\n    \"setupFiles\": [\r\n      \"<rootDir>/config/polyfills.js\"\r\n    ],\r\n    \"testPathIgnorePatterns\": [\r\n      \"<rootDir>[/\\\\\\\\](build|docs|node_modules|scripts)[/\\\\\\\\]\"\r\n    ],\r\n    \"testEnvironment\": \"node\",\r\n    \"testURL\": \"http://localhost\",\r\n    \"transform\": {\r\n      \"^.+\\\\.(js|jsx)$\": \"<rootDir>/node_modules/babel-jest\",\r\n      \"^.+\\\\.css$\": \"<rootDir>/config/jest/cssTransform.js\",\r\n      \"^(?!.*\\\\.(js|jsx|css|json)$)\": \"<rootDir>/config/jest/fileTransform.js\"\r\n    },\r\n    \"transformIgnorePatterns\": [\r\n      \"[/\\\\\\\\]node_modules[/\\\\\\\\].+\\\\.(js|jsx)$\"\r\n    ],\r\n    \"moduleNameMapper\": {\r\n      \"^react-native$\": \"react-native-web\"\r\n    }\r\n  },\r\n  \"babel\": {\r\n    \"presets\": [\r\n      \"react-app\"\r\n    ]\r\n  },\r\n  \"eslintConfig\": {\r\n    \"extends\": \"react-app\"\r\n  }\r\n```\r\nDependencies:\r\n\"enzyme\": \"^2.7.1\",\r\n \"jest\": \"18.1.0\",\r\n \"react\": \"^15.4.2\",\r\n \"react-dom\": \"^15.4.2\",\r\n \"react-router\": \"^3.0.2\"\r\n\r\nNode v 7.5.0\r\n\r\nAnother variation, propesed by stackOverflow has some interesting results:\r\n```\r\n  jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;\r\n\r\n  it('mock setTimeout test', (done) => { // <--- add argument\r\n    setTimeout(() => {\r\n      console.log('TIME IS UP');\r\n      done(new Error('time is up')); // <--- indicate the test finished with error\r\n    }, 1000);\r\n    // ...\r\n    console.log('I ran after the timer');\r\n    // ...\r\n  });\r\n```\r\n`'I ran after the timer'` gets printed to the console first.\r\nAfterwards the test times out after 10 seconds, printing out:\r\n\r\n> Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/jest/issues/comments/351671626","html_url":"https://github.com/facebook/jest/issues/3211#issuecomment-351671626","issue_url":"https://api.github.com/repos/facebook/jest/issues/3211","id":351671626,"user":{"login":"ReeganExE","id":7277418,"avatar_url":"https://avatars2.githubusercontent.com/u/7277418?v=4","gravatar_id":"","url":"https://api.github.com/users/ReeganExE","html_url":"https://github.com/ReeganExE","followers_url":"https://api.github.com/users/ReeganExE/followers","following_url":"https://api.github.com/users/ReeganExE/following{/other_user}","gists_url":"https://api.github.com/users/ReeganExE/gists{/gist_id}","starred_url":"https://api.github.com/users/ReeganExE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReeganExE/subscriptions","organizations_url":"https://api.github.com/users/ReeganExE/orgs","repos_url":"https://api.github.com/users/ReeganExE/repos","events_url":"https://api.github.com/users/ReeganExE/events{/privacy}","received_events_url":"https://api.github.com/users/ReeganExE/received_events","type":"User","site_admin":false},"created_at":"2017-12-14T10:30:21Z","updated_at":"2017-12-14T10:30:21Z","author_association":"NONE","body":"Thank @davidgilbertson \r\n\r\nI tried with `await new Promise(resolve => setTimeout(resolve, 1));` and it worked.\r\n\r\n```js\r\nit('should trigger onChange', async () => {\r\n    const pin = shallow(<PINInput />);\r\n\r\n    pin.find('input').forEach((input, idx) => input.simulate('change', { target: { value: idx.toString() } }));\r\n\r\n    await new Promise(resolve => setTimeout(resolve, 1));\r\n    expect(pin.state('value')).toBe('0123');\r\n});\r\n```"}}
{"actor":{"display_login":"ReeganExE"}}