Ian
Ian

Reputation: 2610

Invariant Violation: @react-native-community/cookies: Add RNCookieManagerIOS.h and RNCookieManagerIOS.m to your Xcode project

I am receiving this error when running yarn test in my react native project after installing and importing @react-native-cookies/cookies

 Invariant Violation: @react-native-community/cookies: Add RNCookieManagerIOS.h and RNCookieManagerIOS.m to your Xcode project

The import:

import CookieManager from '@react-native-cookies/cookies';

Upvotes: 3

Views: 1217

Answers (2)

stonedauwg
stonedauwg

Reputation: 1407

Piggybacking off @Ian answer (which I upvoted); if you are using Jest you can add this to your Jest setupFiles file:

jest.mock("@react-native-cookies/cookies", () => ({
  set: jest.fn(),
  get: jest.fn(),
  clearAll: async () => {},
}));

Upvotes: 0

Ian
Ian

Reputation: 2610

Mocking it helped:

// __mocks__/@react-native-cookies/cookies.ts

const CookieManager = {
  set: jest.fn(),
  get: jest.fn(),
  clearAll: async () => {},
};

export default CookieManager;

You can also refer to this official issue for more info.

Upvotes: 3

Related Questions