小编Noo*_*oob的帖子

如何使用 React 测试库粘贴剪贴板数据?

我正在尝试将剪贴板中已有的文本粘贴到文本框中,但我不明白如何使用“eventInit”来执行此操作。我已阅读有关如何将文本粘贴到文本框中的文档,但不清楚如何使用 eventInit。

如何使用 userEvent 将剪贴板中的文本粘贴到文本框中?

这是我的代码:

test('Copy id button copies correct id', async () => {
  const { getAllByLabelText, debug, getByText } = render(
    <MockedProvider mocks={mocks} addTypename={false}>
      <History />
    </MockedProvider>
  );

  const textbox = <input type="text" />;
  
  await waitFor(() => new Promise((resolve) => setTimeout(resolve, 0)));

  const button = getAllByLabelText('click to copy id')[0];
  fireEvent.click(button);
  // userEvent.paste(textbox,_,) unsure what to do here...
});
Run Code Online (Sandbox Code Playgroud)

文件文档

testing integration-testing unit-testing reactjs react-testing-library

10
推荐指数
2
解决办法
1262
查看次数

如何禁用 typescript 来使我的 nextjs 构建失败?

运行时出现一堆类型错误yarn next build,例如:

Type error: Property 'href' does not exist on type '{ name: string; }'.

这导致我的构建失败。我可以在 tsconfig 中添加一个命令来防止这种情况发生吗?

javascript typescript reactjs next.js

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

如何使用 Apollo Client 访问应用程序中任何位置的“client”对象?

我有一个使用 Apollo Client v1 的基本应用程序:

const client = new ApolloClient({...

...

<ApolloProvider client={client}>
   <App />
</ApolloProvider>,
Run Code Online (Sandbox Code Playgroud)

我想知道如何让我的应用程序的其余部分访问该client对象,以便他们可以使用client.query?

导出客户端然后将其导入另一个文件中的唯一方法吗?

由于我的应用程序包装在 a 中ApolloProvider,我想可能有一种client使用 Apollo 特定导入进行导入的方法?

apollo reactjs react-apollo apollo-client

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

expect(...).toHaveAttribute 不是函数 - 为什么?

我创建了一些基本测试并遵循 Jests 网站上的入门指南,但 toHaveAttribute 显然不是一个函数

import React from "react";
import { fireEvent, render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import { App } from "../App";

test("allows users to add items to their list", () => {
  const { getByText, getByLabelText, getByTestId } = render(<App />);

  const input = getByLabelText("What needs to be done?");
  userEvent.type(getByTestId("email"), "Hello World!")
  expect(getByTestId("email")).toHaveAttribute("value", "Hello, World!")
})
Run Code Online (Sandbox Code Playgroud)

类型错误:expect(...).toHaveAttribute 不是函数

  10 |   const input = getByLabelText("What needs to be done?");
  11 |   userEvent.type(getByTestId("email"), "Hello World!")
> 12 …
Run Code Online (Sandbox Code Playgroud)

testing unit-testing reactjs jestjs react-testing-library

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