小编Ism*_*rov的帖子

React onFocus 和 onFocusCapture 区别

onFocus我想知道 React events:和之间有什么区别onFocusCapture。我在 React 的文档页面上找不到合适的答案。

<OutlinedInput
    label="price from"
    onFocus={handlePriceFocus}
/>
<OutlinedInput
    label="price to"
    onFocusCapture={handlePriceFocus}
/>
Run Code Online (Sandbox Code Playgroud)

就我而言,它似乎onFocus具有onFocusCapture相同的功能,因为我在使用这两个事件时没有注意到任何差异。

javascript dom-events reactjs

18
推荐指数
1
解决办法
2万
查看次数

测试库中的 getByText、findByText 和 queryByText 有什么区别?

获取元素文本内容的方法有多种:getByTextvs findByTextvs queryByText
有时我对使用哪一个感到困惑。
我在反应本机中有以下示例:

it('should render children', () => {
  const mockedChildComponentTxt = 'Children are rendered';
  const { getByText, findByText, queryByText } = render(
    <MyProvider>
      <div>{mockedChildComponentTxt}</div>
    </MyProvider>,
  );
  expect(queryByText(mockedChildComponentTxt)).toBeTruthy()
});
Run Code Online (Sandbox Code Playgroud)

queryByText虽然getByText失败了,但是findByText有效。

debug()导致:

<RNCSafeAreaView
    onInsetsChange={[Function anonymous]}
    style={
      Object {
        "flex": 1,
      }
    }
>
    <div>
      Children are rendered
    </div>
</RNCSafeAreaView>
Run Code Online (Sandbox Code Playgroud)

为什么findByText在上面的例子中可以工作,但是getByTextqueryByText失败了?

reactjs react-native react-testing-library

13
推荐指数
1
解决办法
7782
查看次数