expo / vector-icons

https://icons.expo.fyi
MIT License
648 stars 114 forks source link

Unable to unit-test @expo/vector-icons: error from node_modules/@expo/vector-icons/src/createIconSet.tsx:110:28 #180

Open seyaobey-dev opened 2 years ago

seyaobey-dev commented 2 years ago

I’m getting this error when I run my test (jest, jest-expo, testing-library/react-native):

TypeError: Cannot read property 'default' of undefined
      at _default (node_modules/@expo/vector-icons/src/createIconSet.tsx:110:28)
      at Object.<anonymous> (node_modules/@expo/vector-icons/src/AntDesign.ts:5:16)
      at Object.<anonymous> (node_modules/@expo/vector-icons/src/Icons.ts:1:1)

The error seems to come from expo vector icons. I believe I have correctly setup my tests:

module.exports = {
    preset: 'jest-expo',
    setupFilesAfterEnv: ['<rootDir>/setupTest.ts'],
    moduleDirectories: ['node_modules', 'src/testing-setup', '__dirname'],
};

And here is my component under test:

describe('PageTest01', () => {
    test('it should render', () => {
        const { getByTestId } = render(<PageTest01 />);
        expect(getByTestId('page')).toBeDefined();
    });
});

Please help me look at this issue: I've been looking for a solution for more than a month, across the net (stackoverflow) and various forums (discord).

Bryant-Anjos commented 2 years ago

Any solution for this problem? I'm having the same issue.

luiz504 commented 11 months ago

I'm facing a close issue, image, The Icons should be the first Text element on this screen.debug snapshot, what I found weird is that the props testID is been not passed to the element.

A workaround but with limitations is: expect(screen.UNSAFE_getByType(MaterialIcons)).toBeOnTheScreen() but it has problems with multiple instances.