-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
utils.js: significant modification of diff behavior #1357
Conversation
Also, I'm unsure if this breaks anything. 😄 |
Updated with some fixes + squished |
35c1580
to
64dfc0b
Compare
I would maybe add some asserts for testing if circular refs are handled at deeper levels. Everything else LGTM. 👍 |
This is awesome improvement!
Is there an (easy) way how to detect special object types like
Is there a way how render this without the enclosing double quotes? If I understand the current implementation correctly, it renders expect({ foo: undefined }).to.eql({ foo: '[undefined]' }); Output based on my understanding (I did not run the code):
IMHO, none of that is a blocker preventing this patch from being landed. |
what is this saying? it was an empty object before and now it's a date? |
Yes, sorry, this was unclear. It’s a diff of the diff output. :P On November 11, 2014 at 13:37:24, Travis Jeffery ([email protected]) wrote:
what is this saying? it was an empty object before and now it's a date? — |
ok but $accessed is a date there there, right? i think it'd probably be a good idea to wrap it with "[]", e.g.: "[Fri Sep 12 2014 23:00:10 GMT-0700 (PDT)]". as is done with undefined. and then we're consistently using [] to show that it's a value. or maybe some other symbol(s) to know that it's not really a string. |
ping @boneskull |
Will do On Mon, Dec 8, 2014 at 3:41 AM, David da Silva Contín <
|
I think it's better, anyway. I was becoming frustrated by seeing my `Date`s and `Function`s represented as objects within the diffs. Even more frustrating is when the diff result *appears to be exactly the same* but the assertion failed anyway. So this is my attempt at making the diffs more friendly and understandable. Summary of changes: - Added inner function `emptyRepresentation()`, which is called in the case that your `Object`, `Function` or `Array` has nothing "in" it. It attempts to make a unique representation of that empty value. - Added private API function `exports.type()`, which can be used to deduce the type of any given value. *I exported this function mainly for testing purposes* - Modified `exports.stringify()` to avoid `JSON.stringify()` in circumstances where `JSON.stringify()` may not be much help. My only concern here is whether or not we should display a string in double-quotes, as to coincide with `JSON.stringify()` behavior. - If `value` is `undefined` or `null`, return `'[undefined]'` or `'[null]'`, respectively. *It's possible to have strings with these same values, which may lead to confusion, but this is an edge case.* - If `value` is a `Date`, return ISO8601 representation w/ formatting - If `value` is not an `Object`, `Function` or `Array`, return result of `value.toString()`. - If `value` is an *empty* `Object`, `Function` or `Array`, return result of function `emptyRepresentation()`. - If `value` has properties, call `exports.canonicalize()` on it, then return result of `JSON.stringify()`. - Modified `exports.canonicalize()` to support the above strategy, with a couple slight differences. The strategy is as follows. If the value... - has already been seen, return string `'[Circular]'` - is `undefined`, return string `'[undefined]'` - is `null`, return value `null`. This differs from the `stringify()` behavior, as to provide a valid JSON representation. - is some other primitive, return the value - is a Date, return wrapped ISO8601 representation - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again. - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()` - Added many tests
Alright, I integrated this with the changes for |
Maybe... If you have an |
utils.js: significant modification of diff behavior
I think it's better, anyway. I was becoming frustrated by seeing my
Date
s andFunction
s represented as objects within the diffs. Even more frustrating is when the diff result appears to be exactly the same but the assertion failed anyway. So this is my attempt at making the diffs more friendly and understandable.Summary of changes:
emptyRepresentation()
, which is called in the case that yourObject
,Function
orArray
has nothing "in" it. It attempts to make a unique representation of that empty value.exports.type()
, which can be used to deduce the type of any given value. I exported this function mainly for testing purposesexports.stringify()
to avoidJSON.stringify()
in circumstances whereJSON.stringify()
may not be much help. My only concern here is whether or not we should display a string in double-quotes, as to coincide withJSON.stringify()
behavior.value
isundefined
ornull
, return'[undefined]'
or'[null]'
, respectively. It's possible to have strings with these same values, which may lead to confusion, but this is an edge case.value
is not anObject
,Function
orArray
, return result ofvalue.toString()
.value
is an emptyObject
,Function
orArray
, return result of functionemptyRepresentation()
.value
has properties, callexports.canonicalize()
on it, then return result ofJSON.stringify()
.exports.canonicalize()
to support the above strategy, with a couple slight differences. The strategy is as follows. If the value...'[Circular]'
undefined
, return string'[undefined]'
null
, return valuenull
. This differs from thestringify()
behavior, as to provide a valid JSON representation.Array
,Object
, orFunction
, return the value of the Thing'stoString()
methodArray
,Object
, orFunction
, return the result of calling this function again.Array
,Object
, orFunction
, return the result of callingemptyRepresentation()
Before:
After: