hapijs / code

Assertion library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange behavior of the 'include' assertion on a string value.

valdemon opened this issue · comments

Hi,

// Following fails and outputs: "Expected 'bc b' to include [ 'b', 'bc' ]"
Code.expect('bc b').to.include(['b', 'bc']);

When the include parameter array order is reversed the assertion succeeds, of course ;)
Tested with the v4.0.0.
Is it a bug or a feature?

I think this is working as expected. include() does all of it's work via Hoek.contain(). The documentation for that method says:

Note: comparing a string to overlapping values will result in failed comparison (e.g. contain('abc', ['ab', 'bc'])).

I think you're running into this situation. I'm going to close this, as I don't think it's an issue, but can reopen if we decide otherwise.

cc: @nlf who maintains hoek and may have something to add.

Ok, thanks for the info, also noticed that about the Hoek.contain() in a meantime.
This simple overlapping example data (ab bc and similar) look quite innocent and not so destructive, so I understand your point.
In a real life test cases it can really fool you though..
At least one must always bear this feature in mind, when constructing assertions.

Thanks for a quick answer!

No problem. To be honest, I really dislike include() a lot. I think it tries to do too many things at once. I would only recommend using it for really simple things.

Maybe it would be reasonable to put the link to the Hoek.contain() doc (or the note from there) to the Code.include doc, just to avoid confusion?

commented

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.