Custom function undefined when running jest -react native

35 views Asked by At

I am writing test for a component where I am using a custom function that I wrote. That function is used in an error message as shown below

export const ERROR_MESSAGES = {
  ENABLE_NOTIFICATIONS_IN_APP_SETTINGS: `Please enable the notifications for ${getBrandName()} in the device settings`,
};

And this is the import of the function

import { getBrandName } from "@utils/CommonUtils";

Here @utils => src/utils/. It is a path alias.

But when I run the test I get this error

TypeError: (0 , _CommonUtils.getBrandName) is not a function

      13 |
      14 | export const ERROR_MESSAGES = {
    > 15 |   ENABLE_NOTIFICATIONS_IN_APP_SETTINGS: `Please enable the notifications for ${getBrandName()} in the device settings`,
         |                                                                                            ^
      16 | };

I searched for the issue and came across this article Jest throws TypeError: (0 , _module.myFunction) is not a function, testing exported functions (non default) with Jest

I checked but I am not mocking that file or function. Any help would be appreciated.

export const getBrandName = () => {
  return "Affluent";
};
0

There are 0 answers