1

这个问题fireEvent.changeText事件不应该在is时调用onChangeText函数,但是当我运行它时:editablefalse

import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { TextInput } from 'react-native';

describe('Button', () => {
  it('should not be editable, if editable is false', () => {
    const handleChangeText = jest.fn();
    const screen = render(<TextInput onChangeText={ handleChangeText } editable={ false } testID={ 'stuff' }/>);
    fireEvent.changeText(screen.getByTestId('stuff'), 'Trigger');
    expect(handleChangeText).not.toHaveBeenCalled();
  });
});

我的测试失败了,因为handleChangeText被调用了。

我用:

  1. "@testing-library/react-native": "7.1.0"
  2. "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz"
4

0 回答 0