chaijs / chai-things

Chai support for assertions on array elements
http://chaijs.com/plugins/chai-things
Other
104 stars 14 forks source link

Breaks Chai all.keys #24

Open ThomWright opened 8 years ago

ThomWright commented 8 years ago

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'

keithamus commented 8 years ago

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:

JohnBaileyN commented 8 years ago

This is sad :(

ThomWright commented 8 years ago

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.

jamespedid commented 8 years ago

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.

ThomWright commented 8 years ago

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

lo1tuma commented 8 years ago

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

wassname commented 8 years ago

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]

drzaal commented 8 years ago

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

wassname commented 8 years ago

Nice!

drzaal commented 8 years ago

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 commented 8 years ago

Okay. It's ready again. Whew.

35

poupryc commented 6 years ago

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

hypeofpipe commented 6 years ago

Seems it doesn't work at all.

master-of-null commented 4 years ago

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

JonnoFTW commented 3 years ago

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

JamieMcNaught commented 1 year ago

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