chai icon indicating copy to clipboard operation
chai copied to clipboard

expect(x).to.include.oneOf["a","b"] behaves as if it's expect(x).to.be.oneOf["a","b"]

Open osmolyar opened this issue 7 years ago • 5 comments

expect(x).to.include.oneOf["a","b"] behaves as if it's expect(x).to.be.oneOf["a","b"]

The assertion " expect("Login IRIS").to.include.oneOf(["","Login"],error);"

results in the following, as if "to.be.oneOf" was used:

AssertionError: Access validation failed -page accessible when not expected: expected 'Login IRIS' to be one of [ '', 'Login' ]

osmolyar avatar Mar 20 '19 16:03 osmolyar

Hi @osmolyar, thanks for your issue 😊

This is expected and I believe this is related to #1241, correct?

If we're accepting contains to work with oneOf I think includes should make sense too.

Please feel free to open a PR for this feature. The core team is currently working on the new version, which is mostly a rewrite and therefore we will not have time to open a PR for this ourselves. This should be just like #1241 though.

lucasfcosta avatar May 27 '19 15:05 lucasfcosta

Hi, is there any progress? I believe it's not expected since it contradicts with examples in docs.

It can also be chained with .contain or .include, which will work with both arrays and strings:

expect('Today is sunny').to.contain.oneOf(['sunny', 'cloudy'])

misha-erm avatar Mar 10 '21 12:03 misha-erm

Hello would like to see progress on this issue They below line does not work expect('Today is sunny').to.contain.oneOf(['sunny', 'cloudy'])

mellester avatar Mar 04 '22 14:03 mellester

4 years later since the original post, same issue

SergeDot avatar Sep 19 '23 04:09 SergeDot

I think this issue was resolved in #1242, since the work was released in version 4.3.0(https://github.com/chaijs/chai/releases/tag/4.3.0), it is expected that the above issue will be resolved in later versions.

In fact, if we use the latest version, the code below passes the test normally.

expect("Login IRIS").to.include.oneOf(["","Login"])
expect('Today is sunny').to.contain.oneOf(['sunny1', 'cloudy'])

developer-bandi avatar Feb 14 '24 18:02 developer-bandi