我試圖使用sinon.spy()
來檢查函數是否已被調用。該函數被稱爲getMarketLabel
,它返回marketLabel
並將其接受到函數中。我需要檢查getMarketLabel
已被調用。我實際調用getMarketLabel
在一個地方,像這樣: {getMarketLabel(sel.get('market'))}
我到目前爲止的代碼是:Sinon Spy檢查函數被稱爲
describe('Check if it has been called',() => {
let spy;
beforeEach(() => {
spy = sinon.spy(getMarketLabel, 'marketLabel');
})
it('should have been called',() => {
expect(spy).to.be.calledWith('marketLabel');
});
});
這是錯誤我收到: TypeError: Attempted to wrap undefined property marketLabel as function
請參見本文的jsfiddle:https://jsfiddle.net/hv8mLwcL/ – DaveDavidson
@DaveDavidson'sinon.spy(getMarketLabel, 'marketLabel' )'無效:'getMarketLabel'不是一個對象,'marketLabel'不是一個函數。 – robertklep