2017-05-05 97 views
0

我有一個文件,這個功能玩笑嘲諷出實施

export const doSomething = (arg1, arg2) => { 
    SomeClass.someFunction() 
    OtherClass.otherFunction() 
} 

我在人們如何模擬的東西上網看了一下,但沒有人解決了我的情況。基本上我在開玩笑測試,我想打電話給

test('sendText to send text with the proper number',() => { 
    doSomething() 
    expect(SomeClass.someFunction).toBeCalled(); 
}) 

我不知道究竟該怎麼做。我在網上看到的所有東西都嘲笑了測試函數頂層的函數,然後將其傳遞到他們想要測試的實際函數中,這與我想要做的非常不同。

SomeClass是我爲跟蹤導入的第三方事物,我只是想驗證它是否被調用。其他類同樣。我怎麼做?

回答

0

你會這樣做嘲笑SomeClass

import doSomething from './../doSomething'; 
import SomeClass from 'module/with/SomeClass'; 

jest.mock('module/with/SomeClass'); 

test('sendText to send text with the proper number',() => { 
    doSomething() 
    expect(SomeClass.someFunction).toBeCalled(); 
}) 

玩笑應該能夠確定第三方模塊的結構,並自動提供嘲笑。