{"action":"created","issue":{"url":"https://api.github.com/repos/mochajs/mocha/issues/2041","repository_url":"https://api.github.com/repos/mochajs/mocha","labels_url":"https://api.github.com/repos/mochajs/mocha/issues/2041/labels{/name}","comments_url":"https://api.github.com/repos/mochajs/mocha/issues/2041/comments","events_url":"https://api.github.com/repos/mochajs/mocha/issues/2041/events","html_url":"https://github.com/mochajs/mocha/issues/2041","id":125214223,"number":2041,"title":"Block-level before hook","user":{"login":"AdamBoxall","id":1453709,"avatar_url":"https://avatars.githubusercontent.com/u/1453709?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamBoxall","html_url":"https://github.com/AdamBoxall","followers_url":"https://api.github.com/users/AdamBoxall/followers","following_url":"https://api.github.com/users/AdamBoxall/following{/other_user}","gists_url":"https://api.github.com/users/AdamBoxall/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamBoxall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamBoxall/subscriptions","organizations_url":"https://api.github.com/users/AdamBoxall/orgs","repos_url":"https://api.github.com/users/AdamBoxall/repos","events_url":"https://api.github.com/users/AdamBoxall/events{/privacy}","received_events_url":"https://api.github.com/users/AdamBoxall/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-01-06T16:40:54Z","updated_at":"2016-08-03T15:57:24Z","closed_at":null,"body":"Is it possible to define a block-level `before()` hook when using parent `beforeEach()` hooks?\r\n\r\nTake the following example:\r\n\r\n```js\r\ndescribe(\"something\", function() {\r\n  beforeEach(function() {\r\n    console.log(\"parent beforeEach\");\r\n  });\r\n\r\n  it(\"should do something\", function() {});\r\n\r\n  describe(\"something else\", function() {\r\n    before(function() {\r\n      console.log(\"child before\");\r\n    });\r\n\r\n    it(\"should do something else\", function() {});\r\n  });\r\n});\r\n```\r\n\r\nWhich produces:\r\n\r\n```\r\n  something\r\nparent beforeEach\r\n    ✓ should do something\r\n    something else\r\nchild before\r\nparent beforeEach\r\n      ✓ should do something else\r\n```\r\n\r\nLogically that does actually make sense: it always runs the `before()` hooks before any `beforeEach()` hooks. Unfortunately that means if you depend on some setup done within a parent `beforeEach()` hook, you cannot use `before()` hooks lower down. If you're doing something relatively expensive that doesn't need to be run before every test in that block, you're still forced to use `beforeEach()`.\r\n\r\nI'm using v2.3.4."},"comment":{"url":"https://api.github.com/repos/mochajs/mocha/issues/comments/237281089","html_url":"https://github.com/mochajs/mocha/issues/2041#issuecomment-237281089","issue_url":"https://api.github.com/repos/mochajs/mocha/issues/2041","id":237281089,"user":{"login":"Sinewyk","id":1826366,"avatar_url":"https://avatars.githubusercontent.com/u/1826366?v=3","gravatar_id":"","url":"https://api.github.com/users/Sinewyk","html_url":"https://github.com/Sinewyk","followers_url":"https://api.github.com/users/Sinewyk/followers","following_url":"https://api.github.com/users/Sinewyk/following{/other_user}","gists_url":"https://api.github.com/users/Sinewyk/gists{/gist_id}","starred_url":"https://api.github.com/users/Sinewyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sinewyk/subscriptions","organizations_url":"https://api.github.com/users/Sinewyk/orgs","repos_url":"https://api.github.com/users/Sinewyk/repos","events_url":"https://api.github.com/users/Sinewyk/events{/privacy}","received_events_url":"https://api.github.com/users/Sinewyk/received_events","type":"User","site_admin":false},"created_at":"2016-08-03T15:57:24Z","updated_at":"2016-08-03T15:57:24Z","body":"I want to say that it doesn't make sense. If mocha give us the means to scope stuff. Then the `beforeEach` of the parent scope should run before the `before` of the child scope."}}
{"actor":{"display_login":"Sinewyk"}}