Unable to add extra information to mocha test object
See original GitHub issueCurrent behavior:
I’m attempting to use mochawesome’s addContext
method to add additional information to my tests. Debugging within the test, addContext
is adding additional properties to the test object (this
or runnable.ctx
, but that information appears to be stripped out by the time it reaches the reporter. I raised this at mochawesome - adamgruber/mochawesome#242 - but it appears to be Cypress-specific.
Desired behavior:
When additional properties are added to the mocha test object, they should be passed to the reporter too.
Steps to reproduce:
Create a passing test and call addContext
:
const addContext = require('mochawesome/addContext');
describe('example context missing', () => {
it('should have context', function () {
expect(1+1).to.eq(2);
addContext(this, 'some context');
});
});
Alternatively, call addContext
on a failed test run by adding this to support/index.js
, (based on #1200, which reported this was working but then follow-up comments say it stopped) and write a failing test elsewhere:
const addContext = require('mochawesome/addContext')
Cypress.on('fail', function(err, runnable) {
addContext(runnable.ctx, 'failed context');
throw err;
});
Versions
Cypress 2.10 running in Electron mochawesome 3.02 Windows 10 1803
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:21 (1 by maintainers)
Top GitHub Comments
Here’s another workaround for screenshots that doesn’t require you to manually construct the screenshot file names:
cypress/support/index.js
cypress/support/hooks.js
cypress/plugins/index.js
Yes. You can use it by creating a custom command this way:
And then, inside a test you can call it this way:
In your example it does not work because of the wrong context passed to addContext. You can check by viewing your tests console logs. It expects the param named as ‘test’. So
addContext({ test: this }, element);
should be enough.Notice that if you use arrow functions they don’t bind the
this
context, so you’ll need to move to an ES5 function.