tj / should.js

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

New assertions: supersetOf & subsetOf #200

Closed rajnathani closed 10 years ago

rajnathani commented 10 years ago
New BDD assertions:

supersetOf

['pepperoni', 'tomatoes', 'onion'].should.be.a.supersetOf(['tomatoes'])

(validation of pizza toppings)

subsetOf

['air-conditioning', 'wifi'].should.be.a.subsetOf(['gym', 'wifi', 'air-conditioning', 'hydro'])

(validation of requirements for an apartment search)

btd commented 10 years ago

Hi. Thanks for Pr, but i will not accept it for 2 reasons:

  1. Yours supersetOf/subsetOf it is one operation: A subset B the same as B superset of A.
  2. What you implemented, already implemented in more common way with .containEql and .containDeep:
> ['pepperoni', 'tomatoes', 'onion'].should.containEql('tomatoes')
{ obj: 
   [ 'pepperoni',
     'tomatoes',
     'onion' ],
  params: { operator: 'to contain \'tomatoes\'' },
  negate: false }
> ['pepperoni', 'tomatoes', 'onion'].should.containDeep(['tomatoes'])
{ obj: 
   [ 'pepperoni',
     'tomatoes',
     'onion' ],
  params: { operator: 'to contain [ \'tomatoes\' ]' },
  negate: false }
> ['pepperoni', 'tomatoes', 'onion'].should.containDeep(['tomatoes', 1])
AssertionError: expected [ 'pepperoni', 'tomatoes', 'onion' ] to contain [ 'tomatoes', 1 ]
rajnathani commented 10 years ago

True. Lesser intuitive syntax, but as long as the core of the library is minimalistic, it sounds fair.