TypeError:测试Svelte Component时,Component不是构造函数

问题描述

我想使用svelte-testing-librarysvelte-htm来测试传递给自定义svelte组件的属性的双向绑定。在测试期间尝试渲染组件时,会抛出此异常:

TypeError: Component is not a constructor

   9 | it("should generate first page",async () => {
  10 |   let pageRows = writable([]);
> 11 |   const { getByRole } = render(
     |                         ^
  12 |     html`<${Pagination} rows=${[1,2,3]} bind:pageRows=${pageRows} />`
  13 |   );
  14 |   const button = getByRole("div");

  at create_fragment (node_modules/svelte-hyperscript/src/h.js:132:21)
  at Object.init (node_modules/svelte/internal/index.js:1454:37)
  at new Component (node_modules/svelte-hyperscript/src/h.js:78:7)
  at render (node_modules/@testing-library/svelte/dist/pure.js:71:21)
  at Object.<anonymous> (Pagination.test.js:11:25)

我制作了一个codeandBox以重现该问题。我根本无法在codeandBox中运行测试,但是您可以将代码下载为zip,然后执行npm install && npm run test

https://codesandbox.io/s/nostalgic-snyder-1k8g0?file=/Pagination.test.js

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)