Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to Override Output Formatting #77

Open
machineghost opened this issue Nov 15, 2013 · 0 comments
Open

Way to Override Output Formatting #77

machineghost opened this issue Nov 15, 2013 · 0 comments

Comments

@machineghost
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant