{"action":"closed","issue":{"url":"https://api.github.com/repos/jasmine/jasmine/issues/846","labels_url":"https://api.github.com/repos/jasmine/jasmine/issues/846/labels{/name}","comments_url":"https://api.github.com/repos/jasmine/jasmine/issues/846/comments","events_url":"https://api.github.com/repos/jasmine/jasmine/issues/846/events","html_url":"https://github.com/jasmine/jasmine/issues/846","id":74166103,"number":846,"title":"Attributes set on the \"this\" keyword inside root beforeAll can no longer be accessed inside describe block","user":{"login":"joswhite","id":7979277,"avatar_url":"https://avatars.githubusercontent.com/u/7979277?v=3","gravatar_id":"","url":"https://api.github.com/users/joswhite","html_url":"https://github.com/joswhite","followers_url":"https://api.github.com/users/joswhite/followers","following_url":"https://api.github.com/users/joswhite/following{/other_user}","gists_url":"https://api.github.com/users/joswhite/gists{/gist_id}","starred_url":"https://api.github.com/users/joswhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joswhite/subscriptions","organizations_url":"https://api.github.com/users/joswhite/orgs","repos_url":"https://api.github.com/users/joswhite/repos","events_url":"https://api.github.com/users/joswhite/events{/privacy}","received_events_url":"https://api.github.com/users/joswhite/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-07T23:47:19Z","updated_at":"2015-05-11T17:30:24Z","closed_at":"2015-05-11T17:30:24Z","body":"<p>Hey, thank you guys so much for maintaining this project! It has helped me out so much! I love Jasmine's \"this\" keyword. While doing some tests and upgrading from Jasmine version 2.2.1 to 2.3.0, I noticed my tests no longer passed because of a change that was made in the way the \"this\" keyword can be used. I want to understand why this change was made, and if the Jasmine team as well as people using Jasmine would support reverting this change. Take for example the following code:</p>\r\n<pre><code>beforeAll(function() {\r\n\tthis.attr = 1;\r\n})\r\n\r\ndescribe('Testing root beforeAll', function() {\r\n\tit('should be able to access \"attr\"', function() {\r\n\t\texpect(this.attr).toEqual(1);\r\n\t});\r\n});</code></pre>\r\n<p>Note that in the test we are setting an attribute on the \"this\" keyword inside a <code>beforeAll</code> function that executes on the root level. Executing this test in version 2.2.1 (both the standalone and npm versions) shows the test as passing. However, in version 2.3.0 the test fails.</p>\r\n<p>Let me explain my argument for why this should be changed to work in the latest version of Jasmine. In Jasmine versions 2.2.1 and 2.3.0 I've noticed that inside any <code>describe</code> block you can access attributes on the \"this\" keyword that were set in the <code>beforeAll</code> function of that <code>describe</code> block, regardless of the nesting level inside the block from which you attempt to access those attributes. It only seems logical that the same rules would apply to <code>beforeAll</code> functions on the root level that set attributes on the \"this\" keyword.</p>\r\n<p>Why is this a big deal? Normally you could just use global variables, or put the <code>beforeAll</code> function inside your <code>describe</code> block, and then you could access the attribute just fine. This doesn't work for me though because I chose to use helper files to avoid redundancy in my code. Inside the helper file a <code>beforeAll</code> on the root level initializes attributes on the \"this\" keyword so they can be accessed by the tests. Since the <code>beforeAll</code> no longer works this way, my only alternative (while still allowing me to keep the same testing framework) is using the <code>beforeEach</code>, which will run before every single <code>it</code> block. Considering that there will be over 100 <code>it</code> blocks in my code, the <code>beforeEach</code> will be run dozens of times, making my test code more inefficient. As such, this appears to be a poor solution. So I'm hoping we could get the previous functionality back. :)</p>\r\n<p>Thank you to all who have read my post. Please comment and let me know what you think.</p>"}}