How to test a prop update on React component

前端 未结 8 550
鱼传尺愫
鱼传尺愫 2020-12-14 05:36

What is the correct way of unit testing a React component prop update.

Here is my test fixture;

describe(\'updating the value\', function(){
                 


        
8条回答
  •  执笔经年
    2020-12-14 06:18

    You can use enzyme to mount components and add props to it:

    import React form 'react';
    import component;
    import {configure, mount} form 'enzyme';
    import Adapter from 'enzyme-adapter-react-16';
    import {expect} from 'chai';
    
    configure({adapter: new Adapter()});
    
    describe('Testing component', () => {
      let wrapper;
      beforeEach(() => {
        component = mount();
      });
      it('should update the state of the component when the value prop is changed', function(){
    
        expect(component.props().children.props.value).toBe(false);
    });
    

提交回复
热议问题