In such situation, without rewriting your logic to use named functions, you don't really have another choice other than declaring the function before the test, e.g.
const foo = i => j => i * j
const foo2 = foo(2)
const bar = () => ({ baz: foo2, boz: 1 })
describe('Test anonymous function equality', () => {
it('+++ bar', () => {
const obj = bar()
expect(obj).toEqual({ baz: foo2, boz: 1 })
});
});
Alternatively, you can check whether obj.bar
is any function, using expect.any(Function)
:
expect(obj).toEqual({ baz: expect.any(Function), boz: 1 })
which might actually make more sense depending on the context of the test.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…