开玩笑更新状态,但测试仍然失败

jest updates the states but test fails anyway

我一直在为我的 Signup 组件编写测试(通过手动测试一切正常)。

问题是,如果我 console.log 状态进入玩笑测试,所有状态都会按应有的方式更新,但测试仍然失败。你能帮我么?提前谢谢你。

signup.test.js

    it('changes the state correctly', () => {

        let wrapper = mount(<Signup />);

        const confirmPasswordValidState = wrapper.state('confirmPasswordValid'); // default false

        expect(confirmPasswordValidState).toEqual(false); // it passes

        wrapper = wrapper.update();        
    
        wrapper.find('#password-test').props().onChange({ target: { name: 'password', value: 'maurosorrentino' }});

        wrapper.find('#confirmPassword-test').props().onChange({ target: { name: 'confirmPassword', value: 'maurosorrentino' }});

        wrapper.find('#email-test').props().onChange({ target: { name: 'email', value: 'maurosorrentino@test.com' }});

        wrapper.find('#name-test').props().onChange({ target: { name: 'name', value: 'maurosorrentino' }});

        wrapper = wrapper.update();

        console.log(confirmPasswordValidState); // false why?
        console.log(wrapper.state()); // states change as they should (so in this case is true)
    
        expect(confirmPasswordValidState).toBeTruthy();

    }); 

我从 console.logs

那里得到这个
  console.log
false                                     // console.log(confirmPasswordValidState);

  console.log                             // console.log(wrapper.state())
{
  email: 'maurosorrentino@test.com',
  name: 'maurosorrentino',
  password: 'maurosorrentino',
  confirmPassword: 'maurosorrentino',
  loading: false,
  emailValid: [
    'maurosorrentino@test.com',
    'maurosorrentino',
    'test.',
    'com',
    index: 0,
    input: 'maurosorrentino@test.com',
    groups: undefined
  ],
  passwordValid: true,
  confirmPasswordValid: true,
  nameValid: true,
  formValid: true,
  message: null,
  formErrors: {
    email: '',
    password: '',
    name: '',
    confirmPasswordValid: '',
    confirmPassword: ''
  }
}

wrapper.state('confirmPasswordValid') 为您提供调用该方法时那部分状态的值。如果以后想获取可能变化的值,需要再次调用该方法。