{"action":"created","issue":{"url":"https://api.github.com/repos/yahoo/react-intl/issues/93","labels_url":"https://api.github.com/repos/yahoo/react-intl/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/yahoo/react-intl/issues/93/comments","events_url":"https://api.github.com/repos/yahoo/react-intl/issues/93/events","html_url":"https://github.com/yahoo/react-intl/issues/93","id":60671094,"number":93,"title":"Intl + Jest + Formatting : \"Cannot read property 'prototype' of undefined\" ","user":{"login":"doomy23","id":3316525,"avatar_url":"https://avatars.githubusercontent.com/u/3316525?v=3","gravatar_id":"","url":"https://api.github.com/users/doomy23","html_url":"https://github.com/doomy23","followers_url":"https://api.github.com/users/doomy23/followers","following_url":"https://api.github.com/users/doomy23/following{/other_user}","gists_url":"https://api.github.com/users/doomy23/gists{/gist_id}","starred_url":"https://api.github.com/users/doomy23/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doomy23/subscriptions","organizations_url":"https://api.github.com/users/doomy23/orgs","repos_url":"https://api.github.com/users/doomy23/repos","events_url":"https://api.github.com/users/doomy23/events{/privacy}","received_events_url":"https://api.github.com/users/doomy23/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-11T14:56:16Z","updated_at":"2015-03-11T15:01:06Z","closed_at":"2015-03-11T15:01:06Z","body":"Hi guys!\r\nI was working on some components that needed unit testing the other day and had to spend a long time to find a workaround for this bug I got while unit testing with Jest : \r\n\r\n```\r\nTypeError: Cannot read property 'prototype' of undefined\r\n        at null.<anonymous> (/home/droberge/git/eventshopper/node_modules/react-intl/node_modules/intl-format-cache/lib/memoizer.js:16:59)\r\n        at exports.default._format (/home/droberge/git/eventshopper/node_modules/react-intl/lib/mixin.js:144:29)\r\n        at exports.default.formatDate (/home/droberge/git/eventshopper/node_modules/react-intl/lib/mixin.js:66:21)\r\n        at src$react$$.default.createClass.render (/home/droberge/git/eventshopper/node_modules/react-intl/lib/components/date.js:21:56)\r\n        at ReactCompositeComponentMixin._renderValidatedComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactCompositeComponent.js:1260:34)\r\n        at wrapper [as _renderValidatedComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactCompositeComponentMixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactCompositeComponent.js:802:14)\r\n        at wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (/home/droberge/git/eventshopper/node_modules/react/lib/ReactMultiChild.js:195:42)\r\n        at ReactDOMComponent.Mixin._createContentMarkup (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:260:32)\r\n        at ReactDOMComponent.Mixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:182:14)\r\n        at ReactDOMComponent.wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (/home/droberge/git/eventshopper/node_modules/react/lib/ReactMultiChild.js:195:42)\r\n        at ReactDOMComponent.Mixin._createContentMarkup (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:260:32)\r\n        at ReactDOMComponent.Mixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:182:14)\r\n        at ReactDOMComponent.wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (/home/droberge/git/eventshopper/node_modules/react/lib/ReactMultiChild.js:195:42)\r\n        at ReactDOMComponent.Mixin._createContentMarkup (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:260:32)\r\n        at ReactDOMComponent.Mixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactDOMComponent.js:182:14)\r\n        at ReactDOMComponent.wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactCompositeComponentMixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactCompositeComponent.js:808:44)\r\n        at wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactCompositeComponentMixin.mountComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactCompositeComponent.js:808:44)\r\n        at wrapper [as mountComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at ReactComponent.Mixin._mountComponentIntoNode (/home/droberge/git/eventshopper/node_modules/react/lib/ReactComponent.js:405:25)\r\n        at ReactReconcileTransaction.Mixin.perform (/home/droberge/git/eventshopper/node_modules/react/lib/Transaction.js:134:20)\r\n        at ReactComponent.Mixin.mountComponentIntoNode (/home/droberge/git/eventshopper/node_modules/react/lib/ReactComponent.js:381:19)\r\n        at Object.ReactMount._renderNewRootComponent (/home/droberge/git/eventshopper/node_modules/react/lib/ReactMount.js:312:25)\r\n        at Object.wrapper [as _renderNewRootComponent] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at Object.ReactMount.render (/home/droberge/git/eventshopper/node_modules/react/lib/ReactMount.js:381:32)\r\n        at Object.wrapper [as render] (/home/droberge/git/eventshopper/node_modules/react/lib/ReactPerf.js:50:21)\r\n        at Object.ReactTestUtils.renderIntoDocument (/home/droberge/git/eventshopper/node_modules/react/lib/ReactTestUtils.js:48:18)\r\n        at Spec.<anonymous> (/home/droberge/git/eventshopper/eventshopper/js/picktickets/components/__tests__/EventSelector.test.jsx:82:35)\r\n        at jasmine.Block.execute (/home/droberge/git/eventshopper/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:1065:17)\r\n        at jasmine.Queue.next_ (/home/droberge/git/eventshopper/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:2098:31)\r\n        at null._onTimeout (/home/droberge/git/eventshopper/node_modules/jest-cli/vendor/jasmine/jasmine-1.3.0.js:2088:18)\r\n        at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)\r\n```\r\n\r\nI found that the error occured in **mixin.js** : the Intl global variable is not defined in unit test so it fails at creating **getDateTimeFormat** : \r\n\r\n```javascript\r\n    getNumberFormat  : intl$format$cache$$.default(Intl.NumberFormat),\r\n    getDateTimeFormat: intl$format$cache$$.default(Intl.DateTimeFormat),\r\n```\r\nOne way to solve it would be to import Intl into the mixin and tell Jest to unmock it, but as it required editing the module I tried to find a workaround and here's what I did : \r\n\r\nInstead of using dates components <ReactIntl.Date> I used {this.**formatDate**(...)} in the component that I test... and I need to do this with Jest : \r\n\r\n```javascript\r\njest.dontMock('intl');\r\njest.dontMock('react-intl');\r\njest.dontMock('intl-format-cache');\r\n\r\ndescribe('EventSelector', function() {\r\n  var Intl, ReactIntl, ReactIntlMixin;\r\n\r\n  beforeEach(function(){\r\n    Intl = require('intl');\r\n    ReactIntl = require('react-intl');\r\n    ReactIntlMixin = ReactIntl.Mixin;\r\n    ReactIntlMixin.getDateTimeFormat = require(\"intl-format-cache\").default(Intl.DateTimeFormat);\r\n```\r\n\r\nI basically redefine **getDateTimeFormat** before each test. \r\nIt works but it's quite annoying. Do you have any better workaround for this issue...\r\n\r\nThank you!"},"comment":{"url":"https://api.github.com/repos/yahoo/react-intl/issues/comments/78280256","html_url":"https://github.com/yahoo/react-intl/issues/93#issuecomment-78280256","issue_url":"https://api.github.com/repos/yahoo/react-intl/issues/93","id":78280256,"user":{"login":"caridy","id":38969,"avatar_url":"https://avatars.githubusercontent.com/u/38969?v=3","gravatar_id":"","url":"https://api.github.com/users/caridy","html_url":"https://github.com/caridy","followers_url":"https://api.github.com/users/caridy/followers","following_url":"https://api.github.com/users/caridy/following{/other_user}","gists_url":"https://api.github.com/users/caridy/gists{/gist_id}","starred_url":"https://api.github.com/users/caridy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caridy/subscriptions","organizations_url":"https://api.github.com/users/caridy/orgs","repos_url":"https://api.github.com/users/caridy/repos","events_url":"https://api.github.com/users/caridy/events{/privacy}","received_events_url":"https://api.github.com/users/caridy/received_events","type":"User","site_admin":false},"created_at":"2015-03-11T15:01:06Z","updated_at":"2015-03-11T15:01:06Z","body":"@doomy23 `Intl.*` is a runtime requirement for react-intl, and it is your responsibility to guarantee that by loading a polyfill if your runtime does not support `Intl`. We can't require it in the mixin because Intl is not a module. More details here: http://formatjs.io/guide/#patch-runtime"}}