colorfy-software / react-native-modalfy

🥞 Modal citizen of React Native.
https://colorfy-software.gitbook.io/react-native-modalfy
MIT License
1.13k stars 46 forks source link

How to test modal components with Jest ? #99

Closed GustavoBonfimS closed 1 year ago

GustavoBonfimS commented 1 year ago

I am trying to test my modal components but i dont know how to mock themodalprop withcloseModalandgetParam` with Jest and Typescript.

my test code:

const modalParams = {
  confirmationType: 'email',
  accessToken: 'test-token',
  userInfo: {
    name: 'John',
  },
};

function mockGetParams(key: string) {
  return modalParams[key];
}

const modalfyMockFunctions = {
  getParam: mockGetParams,
  closeModal: jest.fn(),
};

describe('ConfirmEmailModal', () => {
  it('should render confirmation type correctly', () => {
    render(
      <TestWrapper>
        <ConfirmEmailModal modal={modalfyMockFunctions} />
      </TestWrapper>,
    );
  });
});

my modal component: image

The solution was to stop using typing in the component's Props to be able to make a Mock, but this way is not ideal to solve the problem.

CharlesMangwa commented 1 year ago

hey @GustavoBonfimS! thanks for your patience with this reply. are you facing any difficulties with this task? modalfy doesn't have test covering yet indeed. when it comes to what you were trying to achieve, here you can see what the modal prop each Modal receives looks like, hope that will help you with your mock!