{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel-jest/issues/16","labels_url":"https://api.github.com/repos/babel/babel-jest/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel-jest/issues/16/comments","events_url":"https://api.github.com/repos/babel/babel-jest/issues/16/events","html_url":"https://github.com/babel/babel-jest/issues/16","id":66522953,"number":16,"title":"5.0.1 breaks `jest.dontMock`","user":{"login":"troybetz","id":6295938,"avatar_url":"https://avatars.githubusercontent.com/u/6295938?v=3","gravatar_id":"","url":"https://api.github.com/users/troybetz","html_url":"https://github.com/troybetz","followers_url":"https://api.github.com/users/troybetz/followers","following_url":"https://api.github.com/users/troybetz/following{/other_user}","gists_url":"https://api.github.com/users/troybetz/gists{/gist_id}","starred_url":"https://api.github.com/users/troybetz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/troybetz/subscriptions","organizations_url":"https://api.github.com/users/troybetz/orgs","repos_url":"https://api.github.com/users/troybetz/repos","events_url":"https://api.github.com/users/troybetz/events{/privacy}","received_events_url":"https://api.github.com/users/troybetz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-04-06T04:25:38Z","updated_at":"2015-12-04T18:07:34Z","closed_at":"2015-05-21T06:42:47Z","body":"Looks like the imports are being hoisted above the `jest.dontMock` call, turning them into mocks. Pretty sure this is due to  babel itself, but figured the issue would be more relevant here.\r\n\r\n## [Actual test code](https://github.com/compedit/module-boilerplate/blob/c40fcb87189254ce8f690a51befa780aaef37fa5/src/__tests__/person-test.js)\r\n\r\n```js\r\njest.dontMock('../person');\r\n\r\nimport Person from '../person';\r\n\r\ndescribe('Person', () => {\r\n  it('should create a new person', () => {\r\n    const person = new Person('somebody');\r\n    expect(person.name).toBe('somebody');\r\n  });\r\n\r\n  it('should greet someone', () => {\r\n    const person = new Person('somebody');\r\n    expect(person.greet('someone')).toBe('Hello someone, my name is somebody');\r\n  });\r\n});\r\n```\r\n\r\n## (broken) Compiled output using 5.0.1\r\n\r\n```js\r\n'use strict';\r\n \r\nvar _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };\r\n \r\nvar _Person = require('../person');\r\n \r\nvar _Person2 = _interopRequireWildcard(_Person);\r\n \r\njest.dontMock('../person');\r\n \r\ndescribe('Person', function () {\r\n  it('should create a new person', function () {\r\n    var person = new _Person2['default']('somebody');\r\n    expect(person.name).toBe('somebody');\r\n  });\r\n \r\n  it('should greet someone', function () {\r\n    var person = new _Person2['default']('somebody');\r\n    expect(person.greet('someone')).toBe('Hello someone, my name is somebody');\r\n  });\r\n});\r\n```\r\n\r\n#### [console output for broken tests](https://gist.github.com/compedit/1a81993351d6636cb954)\r\n\r\n## Compiled output using 4.0.0\r\n\r\n```js\r\n\"use strict\";\r\n \r\nvar _interopRequire = function (obj) { return obj && obj.__esModule ? obj[\"default\"] : obj; };\r\n \r\njest.dontMock(\"../person\");\r\n \r\nvar Person = _interopRequire(require(\"../person\"));\r\n \r\ndescribe(\"Person\", function () {\r\n  it(\"should create a new person\", function () {\r\n    var person = new Person(\"somebody\");\r\n    expect(person.name).toBe(\"somebody\");\r\n  });\r\n \r\n  it(\"should greet someone\", function () {\r\n    var person = new Person(\"somebody\");\r\n    expect(person.greet(\"someone\")).toBe(\"Hello someone, my name is somebody\");\r\n  });\r\n});\r\n```\r\n\r\nEntire repo available [here](https://github.com/compedit/module-boilerplate), broken tests are on the [babel-5 branch](https://github.com/compedit/module-boilerplate/tree/c40fcb87189254ce8f690a51befa780aaef37fa5)"},"comment":{"url":"https://api.github.com/repos/babel/babel-jest/issues/comments/162037537","html_url":"https://github.com/babel/babel-jest/issues/16#issuecomment-162037537","issue_url":"https://api.github.com/repos/babel/babel-jest/issues/16","id":162037537,"user":{"login":"tony-kerz","id":1223231,"avatar_url":"https://avatars.githubusercontent.com/u/1223231?v=3","gravatar_id":"","url":"https://api.github.com/users/tony-kerz","html_url":"https://github.com/tony-kerz","followers_url":"https://api.github.com/users/tony-kerz/followers","following_url":"https://api.github.com/users/tony-kerz/following{/other_user}","gists_url":"https://api.github.com/users/tony-kerz/gists{/gist_id}","starred_url":"https://api.github.com/users/tony-kerz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tony-kerz/subscriptions","organizations_url":"https://api.github.com/users/tony-kerz/orgs","repos_url":"https://api.github.com/users/tony-kerz/repos","events_url":"https://api.github.com/users/tony-kerz/events{/privacy}","received_events_url":"https://api.github.com/users/tony-kerz/received_events","type":"User","site_admin":false},"created_at":"2015-12-04T18:07:34Z","updated_at":"2015-12-04T18:07:34Z","body":"i can't seem to get any of the workarounds to work for this:\r\n`package.json`:\r\n```\r\n  \"devDependencies\": {\r\n//...\r\n    \"babel-jest\": \"^6.0.1\",\r\n    \"jest-cli\": \"^0.8.0\",\r\n//...\r\n  },\r\n```\r\n```\r\n  \"scripts\": {\r\n    \"test\": \"BABEL_JEST_STAGE=0 jest\"\r\n  },\r\n```\r\n```\r\n  \"jest\": {\r\n    \"scriptPreprocessor\": \"<rootDir>/node_modules/babel-jest\",\r\n    \"testFileExtensions\": [\"js\"],\r\n    \"moduleFileExtensions\": [\"js\"],\r\n    \"unmockedModulePathPatterns\": [\r\n      \"<rootDir>/node_modules/react\",\r\n      \"<rootDir>/node_modules/react-dom\",\r\n      \"<rootDir>/node_modules/react-addons-test-utils\",\r\n      \"<rootDir>/node_modules/fbjs\"\r\n    ]\r\n  }\r\n```\r\n`shared.js`:\r\n```\r\nimport _ from 'lodash'\r\n\r\nexport function replace(o, old, nu) {\r\n// ...\r\n}\r\n```\r\n`__tests__/shared-test.js` (version-1):\r\n```\r\njest.dontMock('../shared')\r\nconst replace = require('../shared')\r\n\r\ndescribe('replace', () => {\r\n it('works for basic case', () => {\r\n   expect(replace({a: 'a'}, 'a', 'b')).toBe({b: 'a'})\r\n })\r\n})\r\n```\r\nresult:\r\n```\r\nSyntaxError: /Users/tony/git/redux-scratch/mock-server/__tests__/shared-test.js: /Users/tony/git/redux-scratch/mock-server/shared.js: Unexpected token import\r\n```\r\n`__tests__/shared-test.js` (version-2):\r\n```\r\nimport './shared-test-no'\r\nimport replace from '../shared'\r\n\r\ndescribe('replace', () => {\r\n it('works for basic case', () => {\r\n   expect(replace({a: 'a'}, 'a', 'b')).toBe({b: 'a'})\r\n })\r\n})\r\n```\r\n`shared-test-no.js`:\r\n```\r\njest.dontMock('../shared')\r\n```\r\nresult:\r\n```\r\nSyntaxError: /Users/tony/git/redux-scratch/mock-server/__tests__/shared-test.js: Unexpected token import\r\n```\r\n\r\ncan anyone spot my folly?\r\n\r\ncheers,\r\ntony.\r\n\r\n\r\n"}}