chaijs / chai-things

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

Nested looping and ranges #29

Open stevenvachon opened 8 years ago

stevenvachon commented 8 years ago

Nested Looping

array = [ [1], [1] ];
expect(array).to.all.all.equal(1);

but then, how would we handle 3+ levels deep?:

expect(array).to.all(3).equal(1);

...but something less mathematical.

Ranged Looping

expect(array).to.each(startIndex, endIndex).equal(1);

Synonyms

each could also be a nice general synonym for all.

stevenvachon commented 8 years ago

Hello?

keithamus commented 8 years ago

Hey @stevenvachon sorry I missed this one.

Is this a feature request?

Chai itself already has assertions for looking into arrays, for example your first example could be:

chai.expect([ [1], [1] ]).to.all.contain(1)
stevenvachon commented 8 years ago

Yes, a feature request. Interesting on all.contain() -- I'll have to try that one out. But, how about array index ranges?

stevenvachon commented 8 years ago

I'm using this with chai-like:

var obj = { key1:value, key2:value, key3:{key:value} };

expect([ obj, obj ]).to.all.be.like({ key1:value, key2:value });

expect([ [obj], [obj] ]).to.all.all.be.like({ key1:value, key2:value });
stevenvachon commented 5 years ago

...