-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
how to get test data in beforeEach() and afterEach() #797
Comments
I saw #795, and that might help with |
You can achieve this using my proposed code change from #795. It works for afterEach also. You can write something like this: beforeEach(function(){
console.log('beforeEach', this.currentTest.title);
});
afterEach(function(){
console.log('afterEach', this.currentTest.title, this.currentTest.state);
}); |
awesome, let's get it merged then! |
i would love to use this functionality but i am not sure what 'this' is in this context. in my tests, 'this' is undefined. is there a more thorough example? edit: must have been in an update because it works now! thanks :) edit: it works in the beforeEach and afterEach but not inside the test. it would be nice to set currentTest.myValue inside the test for the afterEach to observe. |
@adamduffy You have probably solved this by now but you need to be very careful about scope when dealing with |
|
How to get the state of previous test, in beforeEach hook? |
@Visakeswaran why would you want to do that? just curious? beforeEach only pertains to one test (the current test), not the previous test. |
I need to retrieve the status of the whole suite before closing the browser either before the .quit() method and pass those to BrowserStack (which accepts passed or failed only). My understanding is this would be something we cannot achieve in Mocha yet?! I've tried using the this.*** but couldn't really find a proper solution. Any thoughts? |
I need to get the name of each test in
beforeEach
and the pass/fail status of each finished test inafterEach
. I looked at usingthis.test
, but from there the best thing I found wasthis.test.parent
, which is the suite of tests. That's all well and good, but how do I know which of those tests is the one whose before/after block I'm in?The text was updated successfully, but these errors were encountered: