Automattic / Automattic/expect.js
Way to Override Output Formatting
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 207
- PR merge metrics
- No merged PRs in 30d
Description
Currently if you do something like:
```
expect({foo:1}).to.be({foo:2});
```
you get output like:
```
expected {foo:1} to equal {foo:2}
```
That's great when you have only a single property on your object, but if your objects are full of properties (or even just have one property that's a really long string) the error output quickly becomes difficult to use.
It would be really handy if you could specify the output Expect.js should use. For instance, if the following lines:
```
if (value.toString) {
return value.toString();
}
```
are added to "format" (inside the "i" function) then a user could do:
```
expect({
foo:1
longString: '...',
toString: function() {
return 'foo ' + this.foo;
}
}).to.be({
foo:2
longString: '...',
toString: function() {
return 'foo ' + this.foo;
}
});
```
and get the (much more useful) output:
```
expected foo 1 to equal foo 2
```
(Of course, in a real world scenario that toString method would be defined on the class of our two objects, instead of on each object.)
Would it be possible to get something like this added to Expect.js?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.