我在使用Sinon和綁定方法時遇到了一些困難(https://babeljs.io/docs/plugins/transform-class-properties/)。如何在綁定的React組件方法上使用sinon?
我該如何附加間諜?這裏有一個要點: 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
我還沒有找到一種方法,並選擇了綁定在組件的構造函數 –
誰知道爲什麼有人會downvote呢? – stevens32