-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Unit test fails #70
Comments
@ShinyChang any idea what's the issue here? Any help to resolve this would be much appreciated. |
Hi @mhimaz , this is because |
Thank you so much @ShinyChang!! let me try that and come back to you. |
@mhimaz any luck with this? I've tried mocking |
this is how I solved the issue const createElement = document.createElement.bind(document);
document.createElement = tagName => {
const element = createElement(tagName);
if (tagName === "canvas") {
element.getContext = () => ({});
}
return element;
}; |
Where should this code go? I mean I have the same problem and I'm using jest for unit testing but I didn't get how your solution could help me? It would be great if you could share the main component and the test file. Thank you |
This should go on your beforeEach block. |
@RaffysWeb's solution didn't work for me so I merely mocked the Text-Truncate component in my unit tests:
|
Unit test fails on my component which uses TextTruncate library. I try to mount my component using enzyme and got the following error.
`TypeError: Cannot set property 'font' of null
also the snapshot test fails on my component when rendering using 'react-test-renderer'
const tree = renderer.create(<MyComponent { ...props } />).toJSON(); expect(tree).toMatchSnapshot();
this gives a different error message.
`TypeError: Cannot read property 'style' of null
The text was updated successfully, but these errors were encountered: