tj / should.js

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

Better names/aliases for equality #10

Closed aseemk closed 11 years ago

aseemk commented 13 years ago

I'm thinking of adding these aliases into my fork to improve readability for equality:

foo.should.be(bar);
// strict equality; equivalent to foo.should.equal(bar)
// overloads be() to be both a dummy property and a function

foo.should.match(bar);
// deep equality; equivalent to foo.should.eql(bar)
// overloads match() for non-regexp args

I'm thinking of doing this because it's not obvious at a glance at all the distinction between equal vs eql, and also because should's equal (strict) is different than the native assert's equal (loose).

I kept be as strict equal since, at least to me, strict equality is way more useful, esp. in test code, than loose equality. The result is that both be() and match() are nice semantic names. =)

What do you think? I feel like this improves the already-rocking should grammar.

Cheers, Aseem

P.S. Overloading be() will be a lot harder than match() so I might not be able to implement be() just yet. Implementing issue #9 though may help here.

aseemk commented 13 years ago

Tossing out a few other ideas...

For strict equality (currently equal):

actual.should.be(expected);
actual.should.be.exactly(expected)

For deep equality (currently eql);

result.should.match(template);
result.should.mirror(template);
result.should.duplicate(template);

I still like be best for strict equality, though exactly is a nice alias I may add for times where you just want to be extra explicit. ;)

I like match and mirror equally, so if you feel overloading match isn't a great idea, I can just stick with mirror. I like both because their connotations are both nice and explicit.

wmayner commented 11 years ago

I agree - equal and eql are too similar, and their meaning is not immediately clear.