-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot set property 'fillStyle' of null #21
Comments
Installing and setting up https://www.npmjs.com/package/jest-canvas-mock worked for me |
Its a shame you can't easlier to use with create-react-app though |
@hutber You can use it with CRA I just added |
Is there another fix for this? My test suite is AVA? |
For those of us not using jest, my fix was to install |
Also
|
This totally worked for me. Thanks!! |
A better way is to setup jest to handle this.
|
I still have the issue
and then imported that top of my setupTests.js
but still getting:
here is my component to test
and here is my test
any idea? |
just for others, adding to import to existed setupTest.js didn't work for me but adding it to a new file worked. it's a bit strange but just said. |
Any updates on this? doing the |
none of the above mentioned solutions work for me.
have installed |
This is my current solution. While I'm trying to import
|
For vitejs
import { vi } from "vitest";
/* @ts-ignore */
HTMLCanvasElement.prototype.getContext = () => {
return {
fillStyle: '',
fillRect: vi.fn()
}
}
export default defineConfig({
test: {
setupFiles: ['./vitest.setup.ts'],
}
}); |
This was needed for me in my /* @ts-ignore */
HTMLCanvasElement.prototype.getContext = () => {
return {
fillStyle: '',
fillRect: vi.fn(),
clearRect: vi.fn(),
scale: vi.fn(),
}
} |
Work for me, Thanks. |
Adding the following to jest.mock('lottie-web', () => ({
loadAnimation: jest.fn().mockImplementation(() => ({
play: jest.fn(),
destroy: jest.fn(),
renderer: {
ctx: {
canvas: {
getContext: jest.fn().mockReturnValue({
fillStyle: null
})
}
}
}
}))
})) |
Getting this error for all the test cases when they try to mount the component using enzyme.
It shows error corresponding to the import line "import Lottie from 'lottie-react-web';"
Error:-
With :- import Lottie from 'lottie-react-web';
at ../../common/temp/node_modules/.office.pkgs.visualstudio.com/lottie-web/5.5.2/node_modules/lottie-web/build/player/lottie.js:4165:23
at ../../common/temp/node_modules/.office.pkgs.visualstudio.com/lottie-web/5.5.2/node_modules/lottie-web/build/player/lottie.js:4168:6
at ../../common/temp/node_modules/.office.pkgs.visualstudio.com/lottie-web/5.5.2/node_modules/lottie-web/build/player/lottie.js:4268:2
at ../../common/temp/node_modules/.office.pkgs.visualstudio.com/lottie-web/5.5.2/node_modules/lottie-web/build/player/lottie.js:7:26
The text was updated successfully, but these errors were encountered: