Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Access to the mocha test context inside hooks #139

Open
alecf opened this issue Mar 23, 2018 · 0 comments
Open

Access to the mocha test context inside hooks #139

alecf opened this issue Mar 23, 2018 · 0 comments

Comments

@alecf
Copy link

alecf commented Mar 23, 2018

In the beforeTest/afterTest hooks, the first parameter passed (named test in the docs) is an object that looks a lot like the this.currentTest object that you normally have access to, but it is missing some parts that are useful.

For instance in mocha you can write

afterEach(function() {
   console.log('just finished ', this.currentTest.fullTitle());
});

But in the wdio-mocha-framework hook afterTest, it looks like

afterTest(test) {
   console.log('just finished ', test.fullTitle);
}

But it would be nice to just have access to the actual mocha test here.

My specific use case is that I want to report an error to mocha. (I'm using a tool called Applitools Eyes that does screenshot testing) My existing afterEach() looks like:

afterEach(function() => {
    try {
        // This can fail
        eyes.close();
    } catch(ex) {
      // report the error for this test, but do not bail on the whole suite
      this.test.error(ex)
    }
};

but this is impossible with the wdio afterTest hook, because there is no equivalent of this.test.error

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants