tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 194 forks source link

.containDeep() depends on item order #203

Closed lobodpav closed 10 years ago

lobodpav commented 10 years ago

These asserts work well:

However, changing order of items causes the assert to fail:

I would expect that the order of items in .containDeep() argument does not matter because I want to check if the checked array contains all items in the argument no matter the order.

btd commented 10 years ago

I agree and don't agree in the same time. I assume that array is ordered collection and that is why it check order in which elements presented. In opposite object goes unordered.

lobodpav commented 10 years ago

Good point. Could you mention that in the doc?

I solved this by

var arrayToCheck = [1, 2, 3];
[3, 2].forEach(function(item) {
    arrayToCheck.should.containDeep([item]);
});

but I thought it would be nice if I would not have to write so much boilerplate everywhere in my tests.

btd commented 10 years ago

Agree, about i can add methods like .containEql and .containDeep that just check existence. Any suggestion about name? (it seems switch for method will be not enough, also i am worry how to make it less confusing)

lobodpav commented 10 years ago

Yeah, was thinking about a good name too. First I thought I would rename the existing ones to .containEqlOrdered and .containDeepOrdered. But hard to say how many people adopted these already.

yoshuawuyts commented 10 years ago

I think .containEqlOrdered() and .containDeepOrdered() make the most sense. If you're looking to check something in a certain order, most of the time you'll do a .equal() anyway.

btd commented 10 years ago

I will close this as it already in master (will publish today or at weekend). If you have issues about it, pls create new one in shouldjs/should.js.