我可以编写哪个测试来强制执行以下代码
我喜欢通过测试来强制我的设计,但当我涉及系列时,我总是遇到问题。我想要强制执行的代码如下:
clientInvoices : (client, callback)->
@all (invoices)->
callback invoice \
for invoice in invoices \
when invoice.data.clientId() is client.data._id()
起初我写道:
it 'should get randomid1 invoices', ->
subject.clientInvoices client, (invoices)->
invoices.length.should_be 3
但由于您需要以最少的努力使测试通过,因此您可以通过执行此操作来完成
clientInvoices : (client, callback)->
@all (invoices)-> callback [1,2,3]
此测试 代码位于 Coffee-Script 中,但示例位于 Python、Ruby 中或 JavaScript 都受到赞赏。
I like to have my test to force my design but when I comes to collections I always run into problems. The code I want to force is the following:
clientInvoices : (client, callback)->
@all (invoices)->
callback invoice \
for invoice in invoices \
when invoice.data.clientId() is client.data._id()
At first I wrote:
it 'should get randomid1 invoices', ->
subject.clientInvoices client, (invoices)->
invoices.length.should_be 3
But since you need to make the test pass with the least amount of effort you could make this pass by doing
clientInvoices : (client, callback)->
@all (invoices)-> callback [1,2,3]
The code is in Coffee-Script but examples in Python, Ruby or JavaScript are all appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这没有意义:
我想你的意思一定是
如果是这样的话,那么解决你的困境的方法就是简单地添加更多关于回调收到的
invoices
对象的断言,例如(或者任何测试中断言的正确语法 - 您在示例中使用了
should_be
)。通过这个额外的断言,您可以更轻松地使函数正常工作,而不是让它生成虚假数据。This doesn't make sense:
I think you must mean
If that's the case, then the solution to your quandary is simply to add more assertions about the
invoices
object received by the callback, e.g.(or whatever is the correct syntax for assertions in your test—you used
should_be
in your example). With that extra assertion, it's easier for you to make your function work properly than to have it generate fake data.