Formatting objects in chai.expect errors

…衆ロ難τιáo~ 提交于 2019-12-23 09:02:03

问题


When test fails, where I'm comparing two objects using expect(x).to.deep.equal(y), I'd like to see the actual values in my browser test report. Instead, I see something like this:

AssertionError: expected { Object (x, y, ...) } to deeply equal { Object (x, y, ...) }

So it doesn't really show anything useful.

Is there a way to customize how chai.js formats these objects?


回答1:


You can now configure the max length before an object gets truncated as per the docs:

chai.config.truncateThreshold = 0; // disable truncating



回答2:


Not really. This is hardcoded into Chai.
The following function is their object formatter (source here), which does exactly what you posted:

} else if (type === '[object Object]') {
  var keys = Object.keys(obj)
    , kstr = keys.length > 2
      ? keys.splice(0, 2).join(', ') + ', ...'
      : keys.join(', ');
  return '{ Object (' + kstr + ') }';


来源:https://stackoverflow.com/questions/19424773/formatting-objects-in-chai-expect-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!