我正在尝试将剪贴板中已有的文本粘贴到文本框中,但我不明白如何使用“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
运行时出现一堆类型错误yarn next build,例如:
Type error: Property 'href' does not exist on type '{ name: string; }'.
这导致我的构建失败。我可以在 tsconfig 中添加一个命令来防止这种情况发生吗?
我有一个使用 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 特定导入进行导入的方法?
我创建了一些基本测试并遵循 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) reactjs ×4
testing ×2
unit-testing ×2
apollo ×1
javascript ×1
jestjs ×1
next.js ×1
react-apollo ×1
typescript ×1