componentDidMount() not being hit with shallow
- Dominant language
- JavaScript
- Stars
- 19.8k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
I cannot figure out why `componentDidMount()` is not being hit. I debugged it and it's not hitting my fetchCompanies with this test. And it doesn't matter if I use mount or shallow here.
Honestly I'm pissed that I have to satisfy the HOCs such as react-router or connect but after I've done that below with all that garbage, I should be able to now get this test to pass as I am only checking whether or not I'm rendering a specific child. This test used to be very simple before wrapping it in HOCs.
I'm getting
```
AssertionError: expected 0 to equal 1
Expected :1
Actual :0
```
it doesn't matter if I `dive()` or not either.
But anyway back tot he issue at hand..why it's not hitting `fetchCompany(companyId);` here.
```js
it("contains an interview component", () => {
const company = {...companyStub};
company.id = 10;
const uri = `/api/v1/companies/${company.id}`;
mockGet(uri, company);
const interviewContainer = shallow(
);
const interview = interviewContainer.find(".ft-interview");
expect(interview.length).to.equal(1);
});
```
**InterviewContainer.tsx**
```js
import React, { Component } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { fetchCompany } from '../actions/company/CompanyAsyncActions';
import Interview from './Interview';
import { RootState } from '../store';
import { RouteComponentProps, withRouter } from 'react-router';
class InterviewContainer extends Component> {
componentDidUpdate() {
const { fetchCompany } = this.props;
const { companyId } = this.props.match.params;
fetchCompany(companyId);
}
render() {
const { company } = this.props;
return (company && ) || null;
}
}
const mapState = (state: RootState) => ({
company: state.company.company
});
const mapDispatch = {
fetchCompany
};
const connector = connect(mapState, mapDispatch);
type PropsFromRedux = ConnectedProps
export default withRouter(connect(mapState, mapDispatch)(InterviewContainer));
```
Contributor guide
Assessment
This issue has not been assessed yet.