{"action":"created","issue":{"url":"https://api.github.com/repos/Legitcode/tests/issues/11","labels_url":"https://api.github.com/repos/Legitcode/tests/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/Legitcode/tests/issues/11/comments","events_url":"https://api.github.com/repos/Legitcode/tests/issues/11/events","html_url":"https://github.com/Legitcode/tests/issues/11","id":107154873,"number":11,"title":"Cleanup globals after tests","user":{"login":"geowarin","id":1045636,"avatar_url":"https://avatars.githubusercontent.com/u/1045636?v=3","gravatar_id":"","url":"https://api.github.com/users/geowarin","html_url":"https://github.com/geowarin","followers_url":"https://api.github.com/users/geowarin/followers","following_url":"https://api.github.com/users/geowarin/following{/other_user}","gists_url":"https://api.github.com/users/geowarin/gists{/gist_id}","starred_url":"https://api.github.com/users/geowarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geowarin/subscriptions","organizations_url":"https://api.github.com/users/geowarin/orgs","repos_url":"https://api.github.com/users/geowarin/repos","events_url":"https://api.github.com/users/geowarin/events{/privacy}","received_events_url":"https://api.github.com/users/geowarin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-18T08:20:27Z","updated_at":"2015-09-18T08:54:10Z","closed_at":null,"body":"Hi there!\r\n\r\nThank you so much for the lib, I love the middleware idea and I'm planning to use it on a massive scale.\r\nIn the meantime, I noticed some problems in my test suite because globals are not cleaned up after a test.\r\nThe problem is that some libraries test for the presence of window or document to know if they run in node or in the browser.\r\n\r\nIf you take a look at what mocha-jsdom [does](https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L78-L86) : they have a hook to restore the global values after each test.\r\n\r\nAnother problem is react testing the ExecutionEnvironment.canUseDOM boolean.\r\nIn my experience, you can either put this to true like you did or try to initialise a fake DOM before all your test suites (with mocha --require flag for instance).\r\nMocha-jsdom fails miserably at this because in case of nested component re-rendering, this flag will be reinitialised.\r\n\r\nI just wanted to open the discussion to know if you have any insight about this."},"comment":{"url":"https://api.github.com/repos/Legitcode/tests/issues/comments/141384986","html_url":"https://github.com/Legitcode/tests/issues/11#issuecomment-141384986","issue_url":"https://api.github.com/repos/Legitcode/tests/issues/11","id":141384986,"user":{"login":"geowarin","id":1045636,"avatar_url":"https://avatars.githubusercontent.com/u/1045636?v=3","gravatar_id":"","url":"https://api.github.com/users/geowarin","html_url":"https://github.com/geowarin","followers_url":"https://api.github.com/users/geowarin/followers","following_url":"https://api.github.com/users/geowarin/following{/other_user}","gists_url":"https://api.github.com/users/geowarin/gists{/gist_id}","starred_url":"https://api.github.com/users/geowarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geowarin/subscriptions","organizations_url":"https://api.github.com/users/geowarin/orgs","repos_url":"https://api.github.com/users/geowarin/repos","events_url":"https://api.github.com/users/geowarin/events{/privacy}","received_events_url":"https://api.github.com/users/geowarin/received_events","type":"User","site_admin":false},"created_at":"2015-09-18T08:54:10Z","updated_at":"2015-09-18T08:54:10Z","body":"Thanks for your quick reply!\r\nYou are right, the tests run in node 4.\r\n\r\nHowever, I'm using axios to make http requests for example and I'd like to test requests made within my app in my test suite too.\r\nSo in the browser, axios is using XMLHttpRequest and in node, they use the http library.\r\nIf you look at their [code](https://github.com/mzabriskie/axios/blob/master/lib/core/dispatchRequest.js#L14), they test for presence of XMLHttpRequest, which jsdom puts in the global.\r\n\r\nIt's totally possible to work around this by unsetting specific globals for certain tests but it does not feel like the perfect solution intellectually."}}