question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No standard JS/TS autocompletion in Jest test files

See original GitHub issue

Environment

  1. node -v: v10.15.3

  2. npm -v: 6.9.0

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): 24.7.1

  4. Operating system: Windows 10 Pro

Prerequisite

  • are you able to run jest test from command line? Yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) jest, npm run test

I’m checking out VSCode, as a possible replacement for WebStorm/IntelliJ (they’re both great - just interested in knowing how to use both), so please bare with me if I’ve missed something obvious, such as a configuration setting.

This is a “pretty much” fresh VSCode install. I’ve not tweaked settings outside of installing standard extensions (eslint, test runners, etc), and setting up some keybindings.

Steps to Reproduce

This happens in this repo.

The summary is that if I open a test file in VSCode, it doesn’t seem to get treated completely as a JS/TS file; in particular, it doesn’t have the same level of autocompletion I get when using JS/TS files.

Note in the first screenshot the file is set to “Javascript”, and VSCode not only provides autocompletion, it flags the code after the throw as unreachable.

ss+(2019-04-16+at+12 56 19)

Now note how in the second screenshot, with the file set to " ss+(2019-04-16+at+12 56 47)


I’m trying to tackle these things one issue at a time, but I’ve also run into a couple of other problems with this extension so far:

  • Where do I actually see the output of the test runner? With the repo I linked to, I can’t even run the jest tests, even if I comment out the throw - I just get a red “x”, and can’t find any sign out output.
  • I have no gutter icons - I’m not yet ready to report this as an issue, as I think it’s likely I’m missing a vital configuration setting.

For me, the biggest difference (at least, that matters) between VSCode & IntelliJ/WebStorm is the test runner, which is what I’m hoping VSCode can match (w/ gutter icons and navigation being a big part of this).

Let me know if theses anything else I can do to help with this issue, and thanks in advance for your time 😃

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
BluejacketScottcommented, Apr 20, 2019

I resolved my intellisense problem by nuking my code install on windows: Uninstall vscode Deleted code folder located at %appdata%\code Deleted .vscode folder located at %userprofile%.vscode Reinstalled from website Installed this plugin along with a couple of others.

At the command prompt I typed: react-native init myproj --template typescript

Then cd into myproj and type code . to open the folder in code. Created a test and voila - all is right with the world.

0reactions
taosxcommented, Sep 12, 2020

I resolved my intellisense problem by nuking my code install on windows: Uninstall vscode Deleted code folder located at %appdata%\code Deleted .vscode folder located at %userprofile%.vscode Reinstalled from website Installed this plugin along with a couple of others.

At the command prompt I typed: react-native init myproj --template typescript

Then cd into myproj and type code . to open the folder in code. Created a test and voila - all is right with the world.

The only method that worked for me for a nodejs library with ts-config…I have saved the config just in case and planning to reapply.

Before, even when I managed to make it search for tests it was always showing 1 runned, 1 failed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intellisense for Jest not working in VS code - Stack Overflow
Assuming you have a project of two directories like backend and frontend put this file in them both. Then restart vscode. Autocomplete should...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... no tests exist for this file and it's never required in the test...
Read more >
vscode-jest - Visual Studio Marketplace
Help debug jest tests in vscode. Show coverage information in files being tested. Supports monorepo, react, react-native, vue and various ...
Read more >
B Testing with Jest | Client-Side Web Development
This chapter introduces automated testing using the Jest framework. ... in a separate file to test (as well as auto-complete definitions for Jest!)...
Read more >
Implementing autocomplete with Jest, Express, and MongoDB ...
The __tests__/autocomplete.test.js file lists room names and then renders the component into autocomplete : Tvb rod kqr tpinu dfeil, whhic ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found