2

In my mocha/should functional tests I find myself often writing el.is(':visible').should.eql true

Since I do it so much I was thinking it might make sense to extend should so I can do something like this: el.should.beVisible()

That would allow me to change the internals, too, like say:

beVisible = -> this.is(':visible') or this.hasClass('visible') - in case I am using CSS to toggle the visibility. Or, say I decide to drop jQuery in favour of a different dom manipulation library, this would allow my tests to stay the same.

This is just an example - I often find myself wanting to repeat specific "should" assertions, but I am not sure how to extend it. How do I do this? Is it a bad idea?

The only thing I've tried so far is should.prototype.beSomething = -> console.log 'does not work'

Simon Lang
  • 40,171
  • 9
  • 49
  • 58

0 Answers0