I have a component where the only logic is a conditional:
const SuccessPage = () => {
const { urls } = useSelector(getFeatures);
return urls ? <Success /> : <Failure />;
};
export default SuccessPage;
I then created some tests for this but for some reason I get TypeError: (0 , _reactRedux.connect) is not a function . Maybe I have't mocked useSelector correctly? I'm not sure what the issue is.
import React from 'react';
import { shallow } from 'enzyme';
import { getFeatures } from '../../../selectors/index';
import Success from './success.react';
import Failure from './failure.react';
import SuccessPage from './success-page.react';
jest.mock('react-redux', () => ({
useSelector: jest.fn((fn) => fn()),
}));
jest.mock('../../../selectors/index');
describe('SuccessPage', () => {
it('should render Success if getFeatures returns true', () => {
getFeatureFlags.mockReturnValue(true);
const wrapper = shallow(<SuccessPage />);
expect(wrapper.find(Success).exists()).toBe(true);
});
it('should render Failure if getFeatures returns false', () => {
getFeatureFlags.mockReturnValue(false);
const wrapper = shallow(<SuccessPage />);
expect(wrapper.find(Failure).exists()).toBe(true);
});
});