2017-05-05 96 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(); 
}) 

玩笑应该能够确定第三方模块的结构,并自动提供嘲笑。