小编Ber*_*rci的帖子

如何测试反应组件道具(期望组件被调用)

opened={true}我需要测试在单击按钮后是否使用 prop 调用反应组件。我正在使用testing-librarytesting-library/react+ testing-library/jest-dom)。

我用类似的东西嘲笑了组件

import Component from "./path-to-file/component-name"
...
jest.mock("./path-to-file/component-name", () => {
  return jest.fn().mockImplementation(() => {
    return null
  })
})
Run Code Online (Sandbox Code Playgroud)

我首先尝试过:

expect(Component).toBeCalledWith(expect.objectContaining({"opened": true}))
expect(Component).toHaveBeenCalledWith(expect.objectContaining({"opened": true}))
expect(Component).toHaveBeenLastCalledWith(expect.objectContaining({"opened": true}))
Run Code Online (Sandbox Code Playgroud)

但我得到了Error: expect(jest.fn()).toBeCalledWith(...expected)

同样的事情expect.objectContaining({"opened": expect.anything()})

Expect.objectContaining({"opened":expect.anything()})

甚至对于expect(Component).toBeCalledWith(expect.anything())

期待.anything()

区别在于空数组: 空数组

我也尝试过expect(ChartMenu.mock).toBeCalledWith(expect.anything())。我遇到了不同的错误,但仍然无法工作(这次错误是Error: expect(received).toBeCalledWith(...expected)+ Matcher error: received value must be a mock or spy function嘲笑

谢谢您的建议!

编辑:这是我要测试的组件的简化版本:

const Component = () => {
  const [chartMenuOpened, setChartMenuOpened] = useState(false)
  return (
      <Flex> …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs react-testing-library testing-library

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

Ag 网格反应下拉列表不显示网格外

使用预输入作为单元格编辑器进行搜索、行和添加。

问题是,当应用预输入选项时,只会显示在表格内。

我试过了overflow: visible,效果就是这样

actions-button-cell:has(.MultiColumn) {
  overflow: visible;
}

.ag-cel:has(.MultiColumn)l {
  overflow: visible;
}

.ag-row:has(.MultiColumn) {
  z-index: 0;
}

.ag-row.ag-row-focus:has(.MultiColumn) {
  z-index: 1;
}


.ag-root:has(.MultiColumn),
.ag-root-wrapper:has(.MultiColumn),
.ag-body-viewport:has(.MultiColumn),
.ag-body-viewport-wrapper:has(.MultiColumn),
.ag-center-cols-clipper:has(.MultiColumn),
.ag-center-cols-viewport:has(.MultiColumn) {
  overflow: visible !important;
} 
Run Code Online (Sandbox Code Playgroud)

在 css 中,这将显示选项而不隐藏,但 aggrid 行的滚动由于溢出而消失:可见。

有没有办法在 agggrid 之外显示下拉选项而不删除滚动

任何帮助将不胜感激

沙盒链接: https://codesandbox.io/s/v1cqbz

css reactjs ag-grid-react react-bootstrap-typeahead

5
推荐指数
1
解决办法
1474
查看次数