I'm trying to implement test for my component that adapt to the light/dark mode using react-native-appearance.
As the most of my others component use this Text component, i've mocked the module globally using setupFiles :
import * as mocking from "react-native-appearance/src/mock";
jest.mock('react-native-appearance', () => mocking);
But would like to test, only for my Text component the dark mode so i tried something like :
const props: Props = {children: "Test", primary: true};
jest.unmock('react-native-appearance')
const mock = jest.fn();
jest.mock('react-native-appearance', () => ({
useColorScheme: mock
}))
describe('<Text>', () => {
describe('Themes', () => {
it('Renders correctly in light theme', () => {
const tree = create(<Text {...props}/>)
expect(tree.toJSON()).toMatchSnapshot();
})
it('Renders correctly in dark theme', () => {
mock.mockReturnValue('dark');
const tree = create(<Text {...props}/>)
expect(tree.toJSON()).toMatchSnapshot();
})
});
})
But this error occured :
TypeError: (0 , _reactNativeAppearance.useColorScheme) is not a function
Is something i'm doing wrong ? Note that i'm using typescript.