How to test react-router with enzyme

后端 未结 3 1230
时光说笑
时光说笑 2020-12-05 13:47

I am using enzyme+mocha+chai to test my react-redux project. Enzyme provides shallow to test component behavior. But I didn\'t find a way to test the router. I am using reac

3条回答
  •  没有蜡笔的小新
    2020-12-05 14:22

    This will only pass if the component is rendered successfully: It works with Redux and react-router including hooks.

    import React from "react";
    
    import { expect } from "chai";
    import { mount } from "enzyme";
    import { MemoryRouter, Route } from "react-router-dom";
    import { createMockStore } from "redux-test-utils";
    import { Provider } from "react-redux";
    
    
    ...
    describe("", () => {
        it("renders the component", () => {
        let props = {
          index: 1,
          value: 1
        };
        let state = {};
    
        const wrapper = mount(
          
            
              
                
              
            
          
        );
    
        expect(wrapper.find(ProcessedFrames.WrappedComponent)).to.have.lengthOf(1);
      });
    });
    

提交回复
热议问题