I have several functions I would like to test with 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")
^^^^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With