You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the input object is small enough it prints the whole object:
> expect({a:1, b:2, c:3, d:4, e:5}).to.have.keys(['a', 'b', 'qwer'])
AssertionError: expected { a: 1, b: 2, c: 3, d: 4, e: 5 } to have keys 'a', 'b', and 'qwer'
But with 7 or more keys it truncates it:
> expect({a:1, b:2, c:3, d:4, e:5, f:6, g:7}).to.have.keys(['a', 'b', 'qwer'])
AssertionError: expected { Object (a, b, ...) } to have keys 'a', 'b', and 'qwer'
It would be nice if it either printed a much larger object than just 7 keys, or it specifically listed the keys that were missing or unexpected, like:
> expect({a:1, b:2, c:3, d:4, e:5, f:6, g:7}).to.have.keys(['a', 'b', 'qwer'])
AssertionError: expected { Object (a, b, ...) } to have keys 'a', 'b', and 'qwer' but was missing key 'qwer' and had unexpected keys 'c', 'd', 'e', 'f', and 'g'.
My project is using 3.5.0 but It also behaves this way in 4.1.2
The text was updated successfully, but these errors were encountered:
@chriswatrous There's a ton of room for improvement regarding failed assertion messages. It's on the road map to make things better in this regard (see #457 and #585). With that said, what test runner are you using? When I tried your example with Mocha, I get the same error message as you plus the diff which shows the missing and unexpected keys:
AssertionError: expected { Object (a, b, ...) } to have keys 'a', 'b', and 'qwer'
+ expected - actual
Regarding the error message truncation specifically, you can set chai.config.truncateThreshold = 0; at the top of your tests, which results in:
AssertionError: expected { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 } to have keys 'a', 'b', and 'qwer'
(The default threshold is 40 characters; 0 disables it, but you could increase to higher number.)
Gonna close this issue because there already seems to be workarounds for this specific issue, and there are already tickets tracking the messaging problems in general.
This is related to #956.
If the input object is small enough it prints the whole object:
But with 7 or more keys it truncates it:
It would be nice if it either printed a much larger object than just 7 keys, or it specifically listed the keys that were missing or unexpected, like:
My project is using 3.5.0 but It also behaves this way in 4.1.2
The text was updated successfully, but these errors were encountered: