【发布时间】:2017-02-04 00:06:44
【问题描述】:
我在使用带有绑定方法的 Sinon 时遇到了一些困难 (https://babeljs.io/docs/plugins/transform-class-properties/)。
我应该怎么附上间谍?这是一个要点: https://gist.github.com/stevens32/b5eee5cc1781a687be03bf80ce8425e0
结果:
bound method spying
√ should be an instance of FormComponent
should spy on boundChangeInput
√ should have calledOnce prop on boundChangeInput from spy
1) should have boundChangeInput.calledOnce true on simulated input change
√ has the correct value
should spy on notBoundChangeInput
√ should have calledOnce prop on notBoundChangeInput from spy
√ should have notBoundChangeInput.calledOnce true on simulated input change
√ has the correct value
6 passing (133ms)
1 failing
1) bound method spying should spy on boundChangeInput should have boundChangeInput.calledOnce true on
mulated input change:
AssertionError: expected false to equal true
+ expected - actual
-false
+true
【问题讨论】:
-
没找到方法,选择在组件的构造函数中绑定函数
-
有人知道为什么有人会否决这个吗?
标签: unit-testing reactjs mocha.js sinon enzyme