jest-canvas-mock icon indicating copy to clipboard operation
jest-canvas-mock copied to clipboard

getImageData returns undefined

Open danielrentz opened this issue 3 years ago • 4 comments

This code line fails in Jest, because getImageData returns undefined:

    const pixel = context.getImageData(1, 1, 1, 1).data;

danielrentz avatar May 20 '21 14:05 danielrentz

Yep. You need to mock the return value.

jtenner avatar May 20 '21 15:05 jtenner

Hi! Thanks ... ok I see I have to look how this entire mocking thing works (I'm new to Jest). Is there a list with methods that need to be mocked, that could be added to the README? I saw the short "Override default mock return value" about "toDataURL" and thought this is somewhat optional or special.

danielrentz avatar May 21 '21 05:05 danielrentz

For the records: The root cause was the settings resetMocks: true in my Jest config which causes to clear all default mocks created by jest-canvas-mock...

danielrentz avatar May 25 '21 14:05 danielrentz

Ah yeah that will do it. Glad you found the issue.

jtenner avatar May 27 '21 11:05 jtenner