question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[mochawesome] Error adding context: Invalid test object.

See original GitHub issue

Hi, will putting add context in file it gives error: [mochawesome] Error adding context: Invalid test object.

Sample code:

var addContext = require('mochawesome/addContext');
var expect = require("chai");
var assert = require('assert');
var uuid = require('uuid/v1');

describe("scenario",function () {
    it('testcase', function () {
        return promise.then(function(result)){
            ///some code
            addContext(this, 'Test Case yet to be implement');
        })
    })
})

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
adamgrubercommented, Mar 7, 2018

Your this inside the then function doesn’t refer to the test object. You need to save a reference to it first. Like so:

it('testcase', function() {
  var _this = this;
  return promise.then(function(res) {
    // whatever
    addContext(_this, 'Blah blah blah');
  });
});
0reactions
vinayak-kaladharcommented, Jan 20, 2022

Sure thanks @adamgruber , it worked! it(‘Verify creation of Shifts for all Hospital type facility roles’, async function(){ addContext(_this, ‘Blah blah blah’); }

@vinayak-kaladhar It should work fine if you replace the arrow function with a regular function declaration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mochawesome/general - Gitter
I've tried without => and I don't get the [mochawesome] Error adding context: Invalid test object. but it doesn't add anything to the...
Read more >
How to add images to mochawesome report using Codeceptjs?
I think the this object you're looking for is this.ctx in Codeceptjs. Try with addContext(this.ctx, imagePath).
Read more >
Code coverage report for node-npmtest-mochawesome ...
INVALID_CONTEXT : errorPrefix + ' Expected a string or an object of shape ... 'value'); } /** * Add context to the test...
Read more >
mochawesome - npm
mocha tests --reporter mochawesome --require mochawesome/register ... Context passed as an object must adhere to the following shape:.
Read more >
Reporters - CodeceptJS
Test names and failures will be printed out on screen. ... Also if you will add Mochawesome helper, then you will able to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found