小编kar*_*sos的帖子

使用 react 测试库测试 react-contenteditable

如何测试这个组件:https : //github.com/lovasoa/react-contenteditable?如何在测试环境中模仿用户操作?我试过以下:

// The given element does not have a value setter
fireEvent.change(sourceContent, {
  target: { value: "New content text" }
});

// This doesn't emit onChange Changes text content but onChange is not fired.
fireEvent.change(sourceContent, {
  target: { textContent: "New content text" }
});

// This doesn't emit onChange. Changes inner html but onChange is not fired.
fireEvent.change(sourceContent, {
  target: { innerHTML: "New content text" }
});
Run Code Online (Sandbox Code Playgroud)

以上都是失败的测试。我想如果我改变了innerHTML,那么提供的函数onChange将被触发。这是有这个问题的示例项目:https : //codesandbox.io/s/ecstatic-bush-m42hw?fontsize=14&hidenavigation=1&theme=dark

reactjs react-testing-library

5
推荐指数
3
解决办法
1839
查看次数

异步 thunk 会在测试中导致警告(包含在 act 中)

当尝试测试调度异步 thunk 的组件时,我收到以下警告。它们是由于测试完成后执行的更新而显示的。

  console.error
    Warning: An update to App inside a test was not wrapped in act(...).
    
    When testing, code that causes React state updates should be wrapped into act(...):
    
    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */
    
    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
        at App (/home/karlosos/Dev/nokia/playground/testing-redux/src/App.tsx:6:34)
        at Provider (/home/karlosos/Dev/nokia/playground/testing-redux/node_modules/react-redux/lib/components/Provider.js:19:3)
        at Wrapper (/home/karlosos/Dev/nokia/playground/testing-redux/src/testUtils.tsx:11:22)

      at printWarning (node_modules/react-dom/cjs/react-dom.development.js:86:30)
      at error (node_modules/react-dom/cjs/react-dom.development.js:60:7) …
Run Code Online (Sandbox Code Playgroud)

redux react-redux react-testing-library redux-toolkit

3
推荐指数
1
解决办法
978
查看次数

Jsoup 在我的代码中添加空格

我的问题是 jsoup 破坏了我的 html 代码。我正在从 url 下载网站,稍微更改一下并在 WebView 中显示它。

Jsoup 在代码中添加格式化并导致问题:

在html之前:http: //jsfiddle.net/zr3xtus9/

<div class="ctr-element"><div class="ctr-content" style="z-index: 100; margin: 0px; left: 0px; top: 0px; visibility: visible; position: relative;"><div class="ctr-textWrapper" style="text-align: center; line-height: 1; font-size: 124px;" spellcheck="false"><span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer0">&nbsp;P</span><span style="font-size: 124px; color: rgb(245, 230, 93); font-family: capture_it_2;" id="object13textContainer1">arty</span></div></div></div>
Run Code Online (Sandbox Code Playgroud)

html之后:http: //jsfiddle.net/5kv47sny/

 <div class="ctr-element">
  <div class="ctr-content" style="z-index: 100; margin: 0px; left: 0px; top: 0px; visibility: visible; position: relative;">
   <div class="ctr-textWrapper" style="text-align: center; line-height: 1; …
Run Code Online (Sandbox Code Playgroud)

android jsoup

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