Replies: 1 comment
-
Usually "completely identical" means javascript object identity and this would work: const f = () => {};
expect(f).toBe(f) However, I'm guessing this is not what you meant. Alternative would be to simply compare const f = () => {};
const g = () => {};
expect(f.toString()).toBe(g.toString()) Or if you want to compare two functions' outputs for the same input, then you need to generate input by yourselves. Something like fast-check https://github.com/dubzzz/fast-check would help this type of testing, for example: const f = (x) => x + 1;
const g = (y) => 1 + y;
fc.assert(
fc.property(fc.integer(), (x) => {
expect(f(x)).toBe(g(x))
}),
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to determine whether two anonymous functions are completely identical. Is that possible? I tried
toEqual
but returnsfalse
.Beta Was this translation helpful? Give feedback.
All reactions