Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests present errors about types, inconsistently #22

Closed
clark-lindsay opened this issue Sep 23, 2020 · 1 comment
Closed

Tests present errors about types, inconsistently #22

clark-lindsay opened this issue Sep 23, 2020 · 1 comment

Comments

@clark-lindsay
Copy link

Hey! To preface my issue, I am new to Svelte, and so this is my first time jumping through most of these hoops.

Following the Svelte guide for setting up a TypeScript project, I built myself a script to set up a minimal project with a single test for the "Hello World" App component that the default template comes with. I followed the testing setup guide from testing-library, which is what brought me here.

I can run the script to build a new project, cd into it, and run the test with yarn jest, and it passes. If I then edit the test file in any way, say adding an extra 'expect(5).toEqual(5);`, then the tests blow up at me and tell me that they "cannot find name 'test'" and ask me if I forgot to install type definitions.

Screen Shot 2020-09-23 at 7 17 41 PM

If I remove the "offending" change, the issue persists. If I also delete the node_modules folder and run yarn install again, then the test will pass.

Here is a repository with an app fresh off the presses from the script, which I was just able to reproduce the issue with on my system (macOS 10.15.5).

I would hugely appreciate any help that you are able to give. Please let me know if you need any more information!

@DennisSkoko
Copy link

I'm a bit late but maybe it can help someone else who is struggling on this like me. I had the same issue (except that the errors for me were consistent) and tried following the steps TypeScript was writing, adding jest to types. However after adding it, I had another error regarding svelte and saw that the base tsconfig (the one that is extended from @tsconfig/svelte/tsconfig.json) had svelte to the types array, so I needed to specify both jest and svelte, like this:

{
  "extends": "@tsconfig/svelte/tsconfig.json",
  "compilerOptions": {
    "types": ["jest", "svelte"]
  },

  "include": ["src/**/*"],
  "exclude": ["node_modules/*", "__sapper__/*", "public/*"]
}

After looking at your tsconfig.json and saw that you didn't specify the types option. I would recommend trying adding this and see if this helps. I can't really explain the inconsistent errors but hopefully the errors will be consistently gone for you after adding this option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants