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

When stringifying args, use a testdouble's name if it has one #21

Closed
BaseCase opened this issue Sep 10, 2015 · 1 comment
Closed

When stringifying args, use a testdouble's name if it has one #21

BaseCase opened this issue Sep 10, 2015 · 1 comment

Comments

@BaseCase
Copy link

If I want to verify that a testdouble object is called with an argument of another testdouble, it might be nice to show the name of the argument testdouble in the error message. An example:

Given:

var foo = td.create('named_foo');
var bar = td.create('named_bar');
td.verify(bar(foo));

the error message will be:

Error: Unsatisfied verification on test double `named_bar`.

  Wanted:
    - called with `(undefined)`.

  But there were no invocations of the test double.

It could be useful if the error message instead had the line:

    - called with `(named_foo)`.

This is related to a twitter conversation where toString() is also mentioned; I'm not 100% sure how that plays into it but that will probably become clear when I check out the source a bit more.

@searls
Copy link
Member

searls commented Sep 10, 2015

Don't worry about the toString() stuff, I was being overly paranoid. Since a testDouble itself is just a function, I'd add a toString() prop to it to implement this (in the event that a name is set).

> foo = function(){}
> foo.toString = function() { return 'such a foo'; }
> s = "hi" + foo + "bye"
'hisuch a foobye'

So my vote is that wherever we're setting the name now, also add a quick testDouble.toString ||= -> name

@searls searls closed this as completed in 3f2b215 Sep 13, 2015
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

2 participants