【发布时间】:2019-08-01 07:57:56
【问题描述】:
我在尝试使用 react-testing-library 测试 React.Suspense 时遇到一个奇怪的错误。该错误只是说“不支持”,但没有对问题提供任何真正的洞察力。我按照Kent Dodds did on youtube的例子。
我发布了full code of my problem on github here,但这里是测试代码的快照:
import React from "react";
import { render, waitForElement, cleanup } from "react-testing-library";
import MyOtherPackageThing from "my-package/lib/my-thing";
import LazyThing from "../src/index";
afterEach(cleanup);
test("it works", async () => {
const { getByText, debug } = render(<MyOtherPackageThing />);
await waitForElement(() => getByText("my thing"));
expect(getByText("my thing"));
});
describe("these fail with 'Not Supported'", () => {
test("it lazy loads a local component", async () => {
const LazyLocalThing = React.lazy(() => import("../src/LocalThing"));
const { getByText, debug } = render(
<React.Suspense fallback="Loading...">
<LazyLocalThing />
</React.Suspense>
);
debug();
await waitForElement(() => getByText("my local thing"));
debug();
expect(getByText("my local thing"));
});
test("it says not supported, like wtf", async () => {
const { getByText, debug } = render(<LazyThing />);
debug();
await waitForElement(() => getByText("my thing"));
debug();
expect(getByText("my thing"));
});
});
【问题讨论】:
-
您能否分享有关某个问题的更多详细信息?我有一些错误,在
my-consumer-pkg中尝试yarn jest时,我可以看到一些长日志。也许您应该在该测试包中打开一个问题,因为在这里很难找到帮助,这是一个高度专业化的问题。 -
@zishe 当然,你想知道什么? github 中的代码有一个关于如何重现的自述文件。我把所有东西都放在了
run.sh,所以你设置它应该没有任何问题。 -
我创建了一个问题 github.com/benmonro/not-supported-rtl-suspense/issues/1 ,我没有看到任何
run.sh文件。
标签: reactjs testing jestjs react-testing-library react-suspense