2

在我的mocha / should功能测试中,我发现自己经常写 el.is(':visible').should.eql true

因为我做了这么多,所以我认为扩展可能是有意义的,should所以我可以做这样的事情:el.should.beVisible()

这也可以让我改变内部结构,比如:

beVisible = -> this.is(':visible') or this.hasClass('visible')- 如果我使用 CSS 来切换可见性。或者,假设我决定放弃 jQuery 以支持不同的 dom 操作库,这将使我的测试保持不变。

这只是一个例子——我经常发现自己想要重复特定的“应该”断言,但我不确定如何扩展它。我该怎么做呢?这是个坏主意吗?

到目前为止我唯一尝试过的是should.prototype.beSomething = -> console.log 'does not work'

4

0 回答 0