1

Running karma tests using mocha, chai, sinon (and sinon-chai). I have test with a spy

describe('addUser', function(){
    it('should add user', inject(function(UsersModel){
      var dataSpy = sinon.spy(UsersModel, 'userAdditionalData');

      userData = {...};
      authData = {...};
      UsersModel.someMethod();

      dataSpy.should.have.been.calledWith(authData, userData);
    }));
});

And on failure I get the output: "message": "expected userAdditionalData to have been called with arguments [object Object], [object Object]"

How can I get the reporter to give me the details of these objects?

AdrienF
  • 859
  • 1
  • 6
  • 19
  • possible duplicate of [How can I display a JavaScript object?](http://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object) (specifically [this answer](http://stackoverflow.com/a/4293047/5195629) will be useful) – Shadowen Aug 17 '15 at 16:16
  • I don't think this is a duplicate -the reporting is done much deeper than my code, I don't think I can add `JSON.stringify` myself -unless I create my own reporter maybe. My question is actually the same as [Karma reporter with grunt prints object instead of describe strings](http://stackoverflow.com/questions/26064460/karma-reporter-with-grunt-prints-object-object-instead-of-describe-strings), but using mocha, chai and sinon instead of jasmine – AdrienF Aug 17 '15 at 16:18
  • I think you have to use a custom reporter in any case, since the reporter is the one responsible for choosing what text to print out. If you don't like the format they use, then make a custom one! [James answer](http://stackoverflow.com/questions/32055075/karma-reporter-with-mocha-chai-sinon-prints-object-object-instead-of-describ/32055904#32055904) seems to lead in that direction. – Shadowen Aug 17 '15 at 17:04

1 Answers1

0

There seem to be either two ways people are handling this, using a simple 3rd party reporter such as https://www.npmjs.com/package/mocha-spec-json-reporter which dumps it to a file or just console.log(JSON.stringify(['fail', test])); to the console for it. I guess that is a personal coding preference.

James
  • 1,514
  • 12
  • 30