How to test a function that returns functions?
<p>Here I have a function <code>generateBlocks</code> that takes in an array <code>blocks</code> and a function <code>onBlockClick</code>. It returns an array of object where each object has two properties <code>label</code> and <code>onClick</code>. </p>

<pre><code>function generateBlocks(blocks, onBlockClick){
   return blocks.map(block =&gt; (
     {
        label: block.label,
        onClick: ()=&gt;onBlockClick(block.name)
     }
 ))
}
</code></pre>

<p>I'm unable test it's return value.
Here's the test case:</p>

<pre><code>const blocks = [{label: "A", name: "a"}, {label: "B", name: "b"}];
const onBlockClick = someFunction(){};

expect(generateBlocks(blocks, onBlockClick)).to.deep.equal(expected)
</code></pre>

<p>I cannot create <code>expected</code> as <code>[[{label: "A", onClick: ()=&gt;onBlockClick("A")},...]</code> because function reference will be different.</p>

<p>So how do I refactor generateBlocks function to make it testable?</p>