i18n always null when run unit test #1957
-
I have a pure function look like this
The test look like:
But got This is my config file:
and I use it in
When I write unit test for it, I always get i18n is null. How can I fix it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The You'll likely just want to test the Something like below should suffice (assuming you use jest.mock('next-i18next', () => ({
i18n: { t: (input: string) => input },
}));
it('validates a user email', () => {
const result = validateUserEmail(undefined as any);
expect(result).toEqual([false, 'modallogin.validate.email-required']);
}); This mocks the As a sidenote, with your current If you're not sure whether - export function validateUserEmail(email: string): [boolean, string] {
+ export function validateUserEmail(email?: string): [boolean, string] { |
Beta Was this translation helpful? Give feedback.
-
OK found the solution.. Added mock in jest config file
Not sure why mock at test file not working |
Beta Was this translation helpful? Give feedback.
OK found the solution..
Added mock in jest config file
Not sure why mock at test file not working