[英]React - sinon testing - getting TypeError: Cannot read property 'substring' of undefined
我想測試該函數是否正確地解構了給定的參數。 功能是:
function testFunc(...args) {
const [nameOfClass, itemName] = args;
return <div className={nameOfClass}>{itemName}</div>
}
我正在使用 mocha、chai 和 sinon 來測試提供給該函數的參數是否正確解構。 但是測試給了我“AssertionError:預計假為真”:
const funcArguments = ['testClass', 'testItemName'];
const spy = sinon.spy();
testFunc(...funcArguments, spy);
expect(spy.calledWithExactly('testClass', 'testItemName')).to.be.true
是解構的錯嗎?
感謝評論中的輸入,我調整了測試代碼以實際調用spy。 現在看起來像這樣,它給出了正確的結果:
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.