I tried to mock jointjs
, which I’m using like this:
const Canvas = () => {
const g = new dia.Graph({}, { cellNamespace: shapes })
const graph = useRef(g)
const paperEl = useRef(null)
useEffect(() => {
const paper = new dia.Paper({
el: paperEl.current,
model: graph.current,
cellViewNamespace: shapes,
interactive: false,
width: '100%',
height: 800,
async: true,
sorting: dia.Paper.sorting.APPROX // how do I have to mock this?
})
return () => {
paper.removeTools()
}
}, [])
return (
<Box
className="paper"
id="paper"
ref={paperEl}
/>
)
}
But with this mock I do get the error TypeError: Cannot read properties of undefined (reading 'APPROX')
jest.mock('jointjs', () => {
return {
dia: {
Graph: jest.fn(),
Paper: jest.fn().mockImplementation(() => ({
model: jest.fn(),
sorting: { APPROX: 'sorting-approximate' }, // <-- this doesn't work
removeTools: jest.fn()
}))
}
}
})