问题
Writing an unit test file and not able to Render Modal components. I am using jest and Enzyme REACTJS
Here is what I have used in previous files for testing
describe("Component Test", () => {
beforeEach(() => (wrapper = mount(<BrowserRouter><Component{...baseProps} /></BrowserRouter>)));
it("renders a modal portal", () => {
const isOpen = wrapper.state("isOpen");
const modalPortal = wrapper.find(".fullmodal");
expect(isOpen).toBeTruthy;
expect(modalPortal).toHaveLength(1);
expect(toJson(wrapper)).toMatchSnapshot();
});
here is an example of render() with a Modal component
<Modal isOpen={this.state.quickFilterModalOpen} style={descriptionModalStyle}>
<div>
<div className='fullmodal'>
<div className='sidemodal_addnew_x' onClick={this.closeModal}>
<FontAwesome name='xbutton' className='fa-times' />
</div>
</div>
error: ReactWrapper::state("isOpen") requires that state
not be null
or undefined
.
Goal is to be able to render Modal components
来源:https://stackoverflow.com/questions/54889810/error-reactwrapperstateisopen-requires-that-state-not-be-null-or-un