React native 开玩笑模仿实现
我有一个具有此功能的文件React native 开玩笑模仿实现,react-native,jestjs,React Native,Jestjs,我有一个具有此功能的文件 export const doSomething = (arg1, arg2) => { SomeClass.someFunction() OtherClass.otherFunction() } 我看过人们如何在网上嘲笑东西,但没有一个能解决我的问题。基本上在我的玩笑测试中我想打电话 test('sendText to send text with the proper number', () => { doSomething() exp
export const doSomething = (arg1, arg2) => {
SomeClass.someFunction()
OtherClass.otherFunction()
}
我看过人们如何在网上嘲笑东西,但没有一个能解决我的问题。基本上在我的玩笑测试中我想打电话
test('sendText to send text with the proper number', () => {
doSomething()
expect(SomeClass.someFunction).toBeCalled();
})
我不知道该怎么做。我在网上看到的所有东西都在测试函数的顶层模拟了一个函数,然后传递到他们想要测试的实际函数中,这与我想要做的非常不同
SomeClass是我为跟踪而导入的第三方东西,我只想验证它是否被调用。另一类也一样。我该怎么做呢?你可以通过模仿
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();
})
Jest应该能够确定第三方模块的结构并自动提供模拟。您可以通过模拟
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();
})
Jest应该能够确定第三方模块的结构并自动提供模拟