chai-things icon indicating copy to clipboard operation
chai-things copied to clipboard

Breaks Chai all.keys

Open ThomWright opened this issue 8 years ago • 16 comments

Chai's built-in all.keys assertions seem to break when I use chai-things - Chai keys

expect({a: "string", b: "string", c: "string"}).to.have.all.keys(["a", "b"])

AssertionError: expected { Object (a, b, ...) } to have a property 'length'

ThomWright avatar Dec 23 '15 15:12 ThomWright

Hey @ThomWright thanks for the issue.

This does seem to be a problem. I'd welcome a PR to fix this if you have the time :smile:

keithamus avatar Dec 23 '15 22:12 keithamus

This is sad :(

JohnBaileyN avatar Jan 15 '16 22:01 JohnBaileyN

PR sent. The Travis build failed, but it seems to be because it hasn't been configured and is trying to build a Ruby project.

ThomWright avatar Jan 25 '16 10:01 ThomWright

This might be a breaking change, but perhaps instead of using the word all, you use the word each.

expect(collection).to.each.have.property("foo", "bar")

instead of

expect(collection).to.each.have.property("foo", "bar")

This makes more sense grammatically as well.

jamespedid avatar Jan 29 '16 17:01 jamespedid

:+1: That would probably be a better solution.

ThomWright avatar Feb 04 '16 09:02 ThomWright

I’ve exactly the same problem. The key/keys assertion isn’t usable at all if chai-things is used.

lo1tuma avatar Feb 10 '16 11:02 lo1tuma

I agree that each is more intuitive than all, seems like a decent idea. You could even make it work for object values.

A workaround for this is omit writing "all", since chai defaults to using it anyway. From the chai docs:

Note, either any or all should be used in the assertion. If neither are used, the assertion is defaulted to all. [1]

wassname avatar Mar 16 '16 07:03 wassname

I tried to fix this. I might have gotten a bit overaggressive with it though.

Side effects include allowing testing over enumerable object properties and the inclusion of synonym 'each'

https://github.com/chaijs/chai-things/pull/35

drzaal avatar Apr 06 '16 00:04 drzaal

Nice!

wassname avatar Apr 06 '16 03:04 wassname

Get unexcited. It's clear there are some implementation decisions in this module which are at odds with the chai implementations.

The 'contains' flag interaction is mandatory for 'any' and has no effect on 'all'

however in default chai the behavior is 'contains' has no effect on 'any', but determines whether 'all' is inclusive or comprehensive.

There is also a difference between the included chai package and most up to date package of chai.

drzaal avatar Apr 06 '16 22:04 drzaal

Okay. It's ready again. Whew. #35

drzaal avatar Apr 08 '16 17:04 drzaal

I would like to ask for news of the issue ^^

poupryc avatar Dec 28 '17 18:12 poupryc

Seems it doesn't work at all.

hypeofpipe avatar Nov 02 '18 12:11 hypeofpipe

It's pretty bad that this is 4+ years old. Just used chai-things and now have to revert. Didn't notice it wasn't maintained

master-of-null avatar Feb 20 '20 15:02 master-of-null

If they aren't going to maintain this plugin it needs to be marked as archived and alternatives given for its use cases.

JonnoFTW avatar Aug 13 '21 02:08 JonnoFTW

Sadly the broken example of this still exists in the Chai documentation: https://www.chaijs.com/api/bdd/#method_all

JamieMcNaught avatar Jul 14 '23 09:07 JamieMcNaught