Description
I am trying to set up svelte-testing-library together with svelte kit and typescript. I followed the documentation, including the instructions for svelte-jester.
However, when I write a test, i get an error when I pass the imported component to the render function.
The error is TS2769: No overload matches this call
.
From what I can see the render function accepts a SvelteComponentTyped<any, any, any>
as its first argument.
The imported component, however, is of type typeof SvelteComponentDev
. (I added the whole message below)
The error can be seen when executing the test script or already the editor (I tried in vscode and webstorm).
No overload matches this call.
Overload 1 of 3, '(component: SvelteComponentTyped<any, any, any>, componentOptions?: SvelteComponentOptions<any> | undefined, renderOptions?: Omit<RenderOptions<typeof import("/home/marcus/dev/test/node_modules/@testing-library/dom/types/queries")>, "queries"> | undefined): RenderResult<...>', gave the following error.
Argument of type 'typeof default' is not assignable to parameter of type 'SvelteComponentTyped<any, any, any>'.
Type 'typeof default' is missing the following properties from type 'SvelteComponentTyped<any, any, any>': $set, $on, $destroy, $$prop_def, and 5 more.
Overload 2 of 3, '(component: SvelteComponentTyped<any, any, any>, componentOptions?: SvelteComponentOptions<any> | undefined, renderOptions?: RenderOptions<Queries> | undefined): RenderResult<...>', gave the following error.
Argument of type 'typeof default' is not assignable to parameter of type 'SvelteComponentTyped<any, any, any>'.
Overload 3 of 3, '(component: SvelteComponentTyped<any, any, any>, componentOptions?: SvelteComponentOptions<any> | undefined, renderOptions?: Omit<RenderOptions<typeof import("/home/marcus/dev/test/node_modules/@testing-library/dom/types/queries")>, "queries"> | undefined): RenderResult<...>', gave the following error.
Argument of type 'typeof default' is not assignable to parameter of type 'SvelteComponentTyped<any, any, any>'.ts(2769)
comp.test.ts(13, 31): Did you mean to use 'new' with this expression?
comp.test.ts(13, 31): Did you mean to use 'new' with this expression?
comp.test.ts(13, 31): Did you mean to use 'new' with this expression?
I also created a repo for reproduction. It is basically just a new svelte kit project with typescript and then I followed the instructions to set up svelte-testing-library: https://github.com/theweekendgeek/svelte-testing-library-ts-example
edit: I had another quick look after seeing #181. I compared the repos and saw that they were using svelte-testing-library
3.0.3
. After installing the exact version number it the typeerror is gone. but when running the tests I get another error:
> jest src
node:internal/errors:465
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of SyntaxError
at new NodeError (node:internal/errors:372:5)
at _write (node:internal/streams/writable:312:13)
at Socket.Writable.write (node:internal/streams/writable:334:10)
at file:///home/marcus/dev/rpg-emu-front/node_modules/svelte-jester/dist/preprocess.js:21:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
1: 0xb09c10 node::Abort() [node]
2: 0xb0c15d [node]
3: 0xd552fe [node]
4: 0xd5671f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
5: 0x15f2179 [node]
FAIL src/components/Button.test.ts
● Test suite failed to run
Command failed: node --unhandled-rejections=strict --abort-on-uncaught-exception "/home/marcus/dev/rpg-emu-front/node_modules/svelte-jester/dist/preprocess.js"
node:internal/errors:465
ErrorCaptureStackTrace(err);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of SyntaxError
at new NodeError (node:internal/errors:372:5)
at _write (node:internal/streams/writable:312:13)
at Socket.Writable.write (node:internal/streams/writable:334:10)
at file:///home/marcus/dev/rpg-emu-front/node_modules/svelte-jester/dist/preprocess.js:21:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
1: 0xb09c10 node::Abort() [node]
2: 0xb0c15d [node]
3: 0xd552fe [node]
4: 0xd5671f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
5: 0x15f2179 [node]
at file:/home/marcus/dev/rpg-emu-front/node_modules/svelte-jester/dist/preprocess.js:21:32 {
code: 'ERR_INVALID_ARG_TYPE'
}
1: 0xb09c10 node::Abort() [node]
2: 0xb0c15d [node]
3: 0xd552fe [node]
4: 0xd5671f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
5: 0x15f2179 [node]
at Object.processSync [as process] (node_modules/svelte-jester/dist/transformer.cjs:115:42)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:619:31)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:822:19)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 3.322 s
Ran all test suites matching /src/i
another edit after comparing again with the referenced repo from #181 I think I was able to resolve the issue. I had to change the extension of the svelte.config.js
to .mjs
and then point the jest config file to it.