Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 开玩笑模仿实现_React Native_Jestjs - Fatal编程技术网

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应该能够确定第三方模块的结构并自动提供模拟