Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jasminewd2 bind this to jasmine.getEnv() instead of an empty object. #22

Closed
ghusse opened this issue Apr 3, 2015 · 4 comments
Closed

Comments

@ghusse
Copy link

ghusse commented Apr 3, 2015

According to the docs, jasmine 2 bind this to a new empty object for each test. This object can be prepared by beforeEach, and then is passed to the test and afterEach method.

That allows to create independent variables for each test, as described in this post: https://gist.github.com/traviskaufman/11131303

The doc explains how it is supposed to work too: http://jasmine.github.io/2.0/introduction.html#section-The_%3Ccode%3Ethis%3C/code%3E_keyword

Now, my problem is that this feature is not available in protractor: instead of being a new empty object, each test receives the jasmine environment (which is always the same).

Probably due to this code:

var flowFinished = flow.execute(function() {
  fn.call(jasmine.getEnv(), asyncFnDone.fulfill);
}, 'Run ' + fnName + ' in control flow');

It is a very important feature for me to be able to get a new object on each test, it allows me to prepare the platform independently for each test (and in the future, run tests in parallel).

Is there a way to fix this?

@ghusse
Copy link
Author

ghusse commented Apr 7, 2015

If I understand the code correctly, a simple fix might be to replace the call to jasmine.getEnv() by a reference to this which corresponds to the jasmine test context.

var that = this;
var flowFinished = flow.execute(function() {
  // this = jasmine test context
  fn.call(that, asyncFnDone.fulfill);
}, 'Run ' + fnName + ' in control flow');

@ghusse
Copy link
Author

ghusse commented Apr 10, 2015

Is it possible to review the pull request? I really need this to fully implement my tests with protractor.

Thanks

@paulintrognon
Copy link

+1, this is a bug I also noticed myself, PR seems right

@juliemr
Copy link
Member

juliemr commented Apr 14, 2015

Finally fixed with c0f13d2!

@juliemr juliemr closed this as completed Apr 14, 2015
juliemr added a commit to angular/protractor that referenced this issue Apr 14, 2015
This improves the control flow schedule messages for debugging
and fixes an issue with the `this` variable inside tests.
See angular/jasminewd#22
bodyduardU pushed a commit to bodyduardU/protractor that referenced this issue Dec 5, 2022
This improves the control flow schedule messages for debugging
and fixes an issue with the `this` variable inside tests.
See angular/jasminewd#22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants