Answer the question
In order to leave comments, you need to log in
Enzyme tests(snapshot) don't work if the component under test has @observer(mobx) annotation, how to fix it?
Hi all! I have a problem with writing tests for a project. The project has store mobx. Enzyme tests (snapshot) do not work if the component under test has an @observer (mobx) annotation.
I get an error:
Test suite failed to run TypeError: Cannot read property 'componentWillReact' of undefined
Test:
const props = {
store: {...store},
};
describe('ViewModal component testing', () => {
it('mount to dom', async () => {
const component = shallow(
<Provider {...props}>
<ViewModal />
</Provider>);
expect(component).toMatchSnapshot();
});
});
@inject('store')
@observer
export default class ViewModal extends React.Component<IProps> {
componentDidMount() {
this.props.store.getItem();
}
render() {
const {item} = this.props.store;
return (
<Row>
{item}
</Row>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question