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
expected: value is number
assertion:
foo.Element(0).Number()
To make it possible, the following changes are needed:
Add AssertionContext.AliasedPath. It will be similar to AssertionContext.Path, but will take into account aliases.
chain.enter() and chain.leave() should update both Path and AliasedPath
chain.clone() should clone both Path and AliasedPath
chain will provide new setAlias(name) method that will replace AliasedPath with a new slice with single element name, and keep Path untouched
To every inspector struct (Array, Object, Number, etc), add Alias() method that accepts a string name and returns receiver; it will just call chain.setAlias.
After this changes, AssertionContext.AliasedPath will automatically contain the value we're interested in. Now we just need to update DefaultFormatter:
add DisableAliases flag (zero by default), which disables new feature (enabled by default)
if aliases are enabled, fill FormatData.AssertPath using AliasedPath instead of Path
And that's it.
We also need to add unit tests:
comprehensive tests for alias support in chain
short unit test (or maybe new assertion in existing test) for every inspector object (Array, Object, etc)
httpexpect is able to print assertion chain path on failure. For example, when you write:
and assertion fails, you will see:
Often it is convenient to create variables when making assertions:
In this case, it would be nice if variables names were reflected in the failure message.
This issue suggest to implement support for aliases, which will work like this:
To make it possible, the following changes are needed:
AssertionContext.AliasedPath
. It will be similar toAssertionContext.Path
, but will take into account aliases.chain.enter()
andchain.leave()
should update bothPath
andAliasedPath
chain.clone()
should clone bothPath
andAliasedPath
chain
will provide newsetAlias(name)
method that will replaceAliasedPath
with a new slice with single elementname
, and keepPath
untouchedAlias()
method that accepts a string name and returns receiver; it will just callchain.setAlias
.After this changes,
AssertionContext.AliasedPath
will automatically contain the value we're interested in. Now we just need to updateDefaultFormatter
:DisableAliases
flag (zero by default), which disables new feature (enabled by default)FormatData.AssertPath
usingAliasedPath
instead ofPath
And that's it.
We also need to add unit tests:
chain
Finally we should add documentation:
The text was updated successfully, but these errors were encountered: