-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Feature request: pass the return values of beforeAll and beforeEach to the test functions #4903
Comments
This comment has been minimized.
This comment has been minimized.
This is similar to the suggestion proposed at #3553. You can instead do something like this:
The describe and it blocks are just functions, so you can just define a variable within the function, and it will be available everywhere within the function scope. Although it's not very clean, I think it's better that to introduce framework-specific (and not very common) conventions as you have suggested here. |
It's highly unlikely we're going to add extra arguments to the test fn (which is reserved for |
thanks for the reply. @d4nyll this is kinda what we are doing in some of our tests.. this is what we try to avoid perhaps a https://nodejs.org/api/async_hooks.html#async_hooks_class_asyncresource solution can be implemented to achieve the same goal (for node >=8). |
I wish @d4nyll .. I tried that and within the promises there are values but somehow scope is no extended to the test itself
|
@cpojer this issue was closed without any solution or explaining comments. Can you explain your position, plz? |
This was the conclusion:
More recent discussion: #7823 |
For anyone struggling with this here is a workaround, until something comes out of #7823 https://blog.angularindepth.com/how-i-was-completely-wrong-about-setting-up-tearing-down-tests-d3f6501d1718 thanks to this person This was the only way I found that could work after trying every which thing with just scope. I did not do exactly as they say, instead just using the classRef and storing my variables from beforeEach/All there and then able to access them in the tests. Put this somewhere for other files to import
import it wherever you need to set some data, then:
in some other file where you need an id or something, import it again and:
|
@d4nyll What you suggest doesn't allow a very useful thing which is extracting the setup logic into a separate function and reuse it in different suits. |
It's not about implementable. It's about stateless. By global variable or namespace property, we definitely could implement the common result from the setting up. But the thing is, we want to keep our tests more independent and as stateless as we can. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I have a situation like this:
when I have many tests it's tedious to write this line on every test (prefer to avoid storing context object on global/describe scopes).
will be nice to have the ability to pass context objects from before hooks to the test functions as well as the after hooks:
The text was updated successfully, but these errors were encountered: