[英]Jest: How to test function that returns a function
I have several functions I would like to test with Jest. 我想用Jest测试几个功能。 All functions are functions that return functions.
所有函数都是返回函数的函数。
A simple example: 一个简单的例子:
export function csl(foo) {
return function(bar) {
return(bar)
};
}
now I want to test if the input = the return is. 现在我想测试输入是否=返回值。 I try it with:
我尝试使用:
expect(() => csl("foo")).toBe("foo") // = received: [Function anonymous]
expect(csl("foo")).toBe("foo") // = received: undefined
How I can test these functions? 如何测试这些功能?
You need to call the returned function 您需要调用返回的函数
expect(csl("foo")("bar")).toBe("bar")
^^^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.