React Testing Library failing test with code 'Font.register...' #2159
Unanswered
mdodge-ecgrow
asked this question in
Q&A
Replies: 1 comment
-
So Your implementation of jest.mock('@react-pdf/renderer', () => ({
// ...
Font: { register: () => null },
})); For further information, You should visit jest docs |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have several components that are creating PDF documents with this library with custom imported fonts. I am registering the fonts like this:
Well, I am starting to write unit tests for all my code using React Testing Library. And on these components I am getting a failing test with the following error:
TypeError: Cannot read properties of undefined (reading 'register')
and it highlights theFont.register
line. Any ideas how I can get around this?I did add this import to my test file and did not see any changes in the test results:
Update
So I just tried adding the 'Font' function to this snippet in my test file:
And my error changed to:
TypeError: _renderer.Font.register is not a function
. I tried to change the mocked function to 'Font.register' but my IDE doesn't seem to like that syntax.Beta Was this translation helpful? Give feedback.
All reactions