Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest is failing for react-native-element-dropdown import #157

Open
akunal1 opened this issue Mar 17, 2023 · 3 comments
Open

Jest is failing for react-native-element-dropdown import #157

akunal1 opened this issue Mar 17, 2023 · 3 comments

Comments

@akunal1
Copy link

akunal1 commented Mar 17, 2023

code :

`import { Dropdown } from 'react-native-element-dropdown';
...
...
..

`

test


import { render, screen } from '@testing-library/react-native';
import React from 'react';

import MockProviders from '../../../__Mocks__/MockProviders';
import Dropdown from '.';

const testId = 'label';
describe('Testing Label component', () => {
  it('Testing Label', () => {
    render(
      <MockProviders brand="valtra">
        <Dropdown
          testID={testId}
          options={{
            value: '1',
            label: 'India',
            imageUrl:
              'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Flag_of_India.png/1024px-Flag_of_India.png',
          }}
          value="2"
          onChange={jest.fn()}
          label="Label"
          placeholder="Select Country"
          searchPlaceholder="Search"
          errorMessage="Mandatory Field"
        />
      </MockProviders>,
    );

    const foundLabel = screen.getByTestId(testId);
    expect(foundLabel).toBeTruthy();
  });
});

Error:

Screenshot 2023-03-17 at 11 48 00 AM

@hoaphantn7604
Copy link
Owner

hi @akunal1 ,
I'm working on it.

@Shail-Patel-1
Copy link

jest.mock('react-native-element-dropdown', () => jest.fn());

can you try adding the above line above describe statement ? @akunal1

@ArnabXD
Copy link

ArnabXD commented Jan 16, 2024

as a temporary solution

    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|svg)$": "<rootDir>/__mocks__/fileMock.js"
    }
// __mocks__/fileMock.js
module.exports = 'test-file-stub';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants