2021年3月18日星期四

Props are not passing to the test cases

I have a simple component, but not able to pass props for my test cases, It was working fine without - withRouter. what could be the reason

Component

const Plugins = ({pluginsData, history}) => {        return (          <ul className="plugin-list">              <li                  appearance="subtle"                  weight="medium"                  className="item"                  onClick={() => history.push(`/list/plugins`)}>Plugins</li>                  {  pluginsData.length                  ? pluginsData.map((item, index) => <li className="up-coming-text" key={index}>{item.plugin}</li>)                  : " No Data" }          </ul>      )  }  

export default withRouter(Plugins)

plugin.test.js

  const pluginsData= [          {              "plugin": "Apps (Coming soon)"          }      ]         const wrapper = shallow(<Plugins pluginsData={pluginsData}/>);    describe('test home page', () => {        it('should render home page successfully', () => {          expect(wrapper).toMatchSnapshot();      });        it('renders correct text in item', () => {          expect(wrapper.find('.up-coming-text').get(0).props.children).toEqual('Apps (Coming soon)');      });        it('renders pluginsData length', () => {          expect(wrapper.find('.up-coming-text')).toBeDefined();          expect(wrapper.find('.up-coming-text').length).toEqual(pluginsData.length);      });    });     

Error

● test home page › renders pluginsData length

expect(received).toEqual(expected) // deep equality    Expected: 1  Received: 0      28 |     it('renders pluginsData length', () => {    29 |         expect(wrapper.find('.up-coming-text')).toBeDefined();  > 30 |         expect(wrapper.find('.up-coming-text').length).toEqual(pluginsData.length);       |                                                        ^    31 |     });    32 |    33 | });      at Object.<anonymous> (ui/src/routes/Explorer/Plugins/plugins.test.js:30:56)  
https://stackoverflow.com/questions/66694262/props-are-not-passing-to-the-test-cases March 18, 2021 at 11:36PM

没有评论:

发表评论