小编Nic*_*rdy的帖子

在 Next 13 中使用 Jest 测试异步服务器组件

在 NextJs 13+ 中,使用实验性 App 文件夹,可以编写异步服务器组件,如文档所述

export default async function Page({ params: { username } }) {
  // Initiate both requests in parallel
  const artistData = getArtist(username);
  const albumsData = getArtistAlbums(username);

  // Wait for the promises to resolve
  const [artist, albums] = await Promise.all([artistData, albumsData]);

  return (
    <>
      <h1>{artist.name}</h1>
      <Albums list={albums}></Albums>
    </>
  );
}
Run Code Online (Sandbox Code Playgroud)

这是一项非常有用的技术,我已经在应用程序的许多页面中实现了。但是,当使用 jest 进行测试时,我发现我无法编写任何能够呈现此默认导出的测试:

it('should render without crashing', async () => {
  ...(setup mocks)
  const { container } = await waitFor(() => render(<Page …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs next.js react-testing-library react-server-components

16
推荐指数
1
解决办法
6642
查看次数

为什么有些Ruby方法需要爆炸而其他方法不是破坏性方法?

例如,array.pop不需要爆炸来永久改变阵列.为什么会这样,如果没有这种一致性,开发这些某些Ruby方法背后的原因是什么呢?

ruby methods

9
推荐指数
1
解决办法
2474
查看次数

为什么 @testing-library/user-event 上不存在清除方法

我正在开发一个 CMS 项目,刚刚遇到一个问题。_userEvent.default.clear is not a function

\n\n
import user from \'@testing-library/user-event\'\n\ntest(\'can edit label\', async () => {\n    createArticleMock()\n    await renderRootAndInitStore(rightNowTeasers, globalInitialState)\n\n    const index = 1\n    const input = screen.getByDisplayValue(labels[index])\n    const newLabel = \'V\xc3\x84RLDEN\'\n    user.clear(input)\n    user.type(input, newLabel)\n\n    expect(await screen.findByDisplayValue(newLabel))\n    user.click(screen.getByTestId(\'settings-form-save\'))\n    await screen.findByText(newLabel)\n})\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我访问时@testing-library/user-event,我看到那些线条

\n\n
// Definitions by: Wu Haotian <https://github.com/whtsky>\nexport interface IUserOptions {\n    allAtOnce?: boolean;\n    delay?: number;\n}\n\nexport interface ITabUserOptions {\n    shift?: boolean;\n    focusTrap?: Document | Element;\n}\n\nexport type TargetElement = Element | Window;\n\ndeclare const userEvent: {\n …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-testing-library user-event

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

如何通过比较javascript中的两个对象数组来更新特定属性?

我在 javascript 中有以下两个对象数组

data1 = [
  {
    id: 123,
    option: "ABC",
    value: "123"
  },
  {
    id: 234,
    option: "DFG",
    value: "234"
  }
];

data2 = [
  {
    id: 123,
    option: "ABC",
    value: "123"
  }
];
Run Code Online (Sandbox Code Playgroud)

当 id 与第二个对象数组匹配时,我想仅在该特定 id 的第一个对象数组中将值(属性)设置为 0。就像下面一样,一旦 id 123 在两个数组中都匹配,那么 data1 数组应该如下所示

data1 = [
  {
    id: 123,
    option: "ABC",
    value: "0"
  },
  {
    id: 234,
    option: "DFG",
    value: "234"
  }
];
Run Code Online (Sandbox Code Playgroud)

如何实现上述场景?

javascript arrays

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