mercredi 22 mai 2019

how would I test if a components prop is equal to another prop function?

I have a component with a prop calling a prop function passing a value. How do I write a test using enzyme for the same?

<LabeledInput
                name='zip'
                onChange={this.props.onChange}
                onBlur={() => this.props.onBlur('zip')}
                isInError={descriptionError}}
              />

it('should call onChange prop', () => {
    const labeledInputs = wrapper.find(LabeledInput);
    let zipInput = labeledInputs.filterWhere(input => input.props().name === 'zip');
    expect(zipInput.props().onChange).to.equal(props.onChange);
  });

  it('should onBlur prop ', () => {
    const labeledInputs = wrapper.find(LabeledInput);
    let zipInput = labeledInputs.filterWhere(input => input.props().name === 'zip');
    expect(zipInput.props().onBlur).to.equal(props.onBlur);
  });


first one (onChange test)works. Second one gives error "AssertionError: expected [Function: onBlur] to equal [Function: proxy]"

Aucun commentaire:

Enregistrer un commentaire