Here I have a function generateBlocksthat takes an array blocksand a function onBlockClick. It returns an array of objects, where each object has two properties labeland onClick.
function generateBlocks(blocks, onBlockClick){
return blocks.map(block => (
{
label: block.label,
onClick: ()=>onBlockClick(block.name)
}
))
}
I can not check its return value. Here's a test case:
const blocks = [{label: "A", name: "a"}, {label: "B", name: "b"}];
const onBlockClick = someFunction(){};
expect(generateBlocks(blocks, onBlockClick)).to.deep.equal(expected)
I cannot create expectedhow [[{label: "A", onClick: ()=>onBlockClick("A")},...], because the function reference will be different.
So, how do I create a reflexor generateBlocks function to make it executable?
source
share