[英]React - sinon testing - getting TypeError: Cannot read property 'substring' of undefined
I want to test if the function destructures the given arguments properly.我想测试该函数是否正确地解构了给定的参数。 The function is:
功能是:
function testFunc(...args) {
const [nameOfClass, itemName] = args;
return <div className={nameOfClass}>{itemName}</div>
}
I am using mocha, chai and sinon to test if arguments provided to that function are properly destructured.我正在使用 mocha、chai 和 sinon 来测试提供给该函数的参数是否正确解构。 However the test give me "AssertionError: expected false to be true":
但是测试给了我“AssertionError:预计假为真”:
const funcArguments = ['testClass', 'testItemName'];
const spy = sinon.spy();
testFunc(...funcArguments, spy);
expect(spy.calledWithExactly('testClass', 'testItemName')).to.be.true
Is it the fault of destructuring?是解构的错吗?
Thanks to the input in the comments, I adjusted the test code to actually call the spy.感谢评论中的输入,我调整了测试代码以实际调用spy。 It looks like it now and it gives the proper result:
现在看起来像这样,它给出了正确的结果:
const funcArguments = ['testClass', 'testItemName'];
const spiedTestFunc = sinon.spy(testFunc);
spiedTestFunc(...funcArguments);
expect(spiedTestFunc.calledWithExactly('testClass', 'testItemName')).to.be.true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.