Material UI + Enzyme testing component

前端 未结 3 1041
一生所求
一生所求 2021-02-04 11:25

I have component in React which I\'m trying to test with Jest, unfortunately test do not pass.

The component code:

import React, {Component} from \'react         


        
3条回答
  •  囚心锁ツ
    2021-02-04 12:29

    It's something different when you're using @material-ui.

    You've to use @material-ui's Built-in API(s). Such as createMount, createShallow, createRender in order to use enzyme's shallow, mount & render.

    These APIs are built on top of enzyme, so you can't use enzyme directly for testing @material-ui.


    Example of Shallow Rendering with @material-ui

    import { createShallow } from '@material-ui/core/test-utils';
    
    describe('', () => {
      let shallow;
    
      before(() => {
        shallow = createShallow(); 
      });
    
      it('should work', () => {
        const wrapper = shallow();
      });
    });
    

    Reference: Official Docs of @material-ui

提交回复
热议问题