开玩笑 - 具有对象为参数的模拟函数
如何模拟一个具有对象作为参数并返回承诺的函数?
示例:
type FuncProps = {
type: 'a' | 'b';
isSelected: boolean;
isDataIncluded: boolean;
};
type Props = {
onDoSomething: ({ type, isSelected, isDataIncluded }: FuncProps) => Promise<void>;
};
当我这样做时,我会遇到错误:
const onDoSomethingMock = jest.fn(({ type: 'a', isSelected: true, isDataIncluded: false }) => Promise.resolve());
How can I mock a function which has an object as an argument and returns a promise?
Example:
type FuncProps = {
type: 'a' | 'b';
isSelected: boolean;
isDataIncluded: boolean;
};
type Props = {
onDoSomething: ({ type, isSelected, isDataIncluded }: FuncProps) => Promise<void>;
};
I get an error when I do this:
const onDoSomethingMock = jest.fn(({ type: 'a', isSelected: true, isDataIncluded: false }) => Promise.resolve());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是:
It should be: