2017-05-18 109 views
6

我已經完全運行之前興農存根callsFake說法

sinon.stub(console, 'log',() => { 
    // Check what the arguments holds 
    // And either console.info it or do nothing 
}); 

例如,添加console.info(arguments)裏邊有以下存根,會告訴我什麼console.log是越來越。

隨着2xx版本我切換到callsFake

sinon.stub(console, 'log').callsFake(() => { 
    // Check what the arguments holds 
    // And either console.info it or do nothing 
}); 

現在,這再正常工作。 console.info(arguments)具有集市價值,並且與console.log傳遞的東西無關。

我在做什麼錯?

+1

嘗試與回報更換callsFake() –

回答

0

您傳遞給callsFake的箭頭函數沒有收到arguments對象,正如您在常規函數中通常所期待的那樣。

MDN

箭頭函數表達式比函數表達式更短的語法,沒有自己的這一點,參數,超級,或new.target。

要麼改變你的箭頭功能到正規的匿名函數(function() {...}),或使用蔓延運營商明確地解開參數:

sinon.stub(console, 'log') 
console.log.callsFake((...args) => { 
    console.info(args) 
});