Reputation: 959
I have a stateless component.
I am matching the snapshot for unit tests.
But it returns null
import React from 'react';
import { shallow } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import StatelessComponent from 'components/elements/StatelessComponent';
describe('<StatelessComponent />', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<StatelessComponent />);
});
it ('should render with default props', () => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
});
export const StatelessComponent = () => (
<div className={styles['container']}>
<div className={styles['description']}>
<FormattedMessage {...emailErrorInfo} />
</div>
</div>
);
exports[`<StatelessComponent /> should render with default props 1`] = `null`;
Upvotes: 0
Views: 357
Reputation: 959
Exporting the Stateless component as a default solved the issue.
const StatelessComponent = () => (
<div className={styles['container']}>
<div className={styles['description']}>
<FormattedMessage {...emailErrorInfo} />
</div>
</div>
);
export default StatelessComponent
Upvotes: 1
Reputation: 2302
import StatelessComponent
like this, because its not a default export
import { StatelessComponent } from 'components/elements/StatelessComponent';
Upvotes: 2