I'm new to WebStorm, and fairly new to Node development. I am working on an existing project, and want to have code completion for my node_modules. More specifically, I'm using Chai and WebStorm doesn't seem to find the .have
member of my expect.to
statement.
This is my code, simplified:
var expect = require('chai').expect;
import {Customer} from '../../app/model/Customer.js';
describe('...', function() {
it('...', function() {
var customer = new Customer();
expect(customer).to.have.property('name');
});
});
I get squiggly lines under the have
call, and WebStorm tells me Unresolved variable have
.
If I F12 on the to
, WebStorm takes me to another node module, shelljs, but I haven't imported that one.
Is this because WebStorm can't resolve everything in javascript?
I've enabled Coding Assistance for NodeJS as per the docs, but that made no difference.
Invoke basic completion By default, WebStorm displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Space or choose Code | Code Completion | Basic from the main menu. To get more suggestions, press Ctrl+Space for the second time (or press Ctrl+Alt+Space ).
WebStorm is generally more efficient at refactoring and testing JavaScript and JavaScript-based code (such as TypeScript). Refactoring optimizes code for efficiency, while unit testing ensures product quality. VS Code still provides these features — but they aren't tailored to JavaScript.
Enable Live EditPress Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Debugger | Live Edit. Select Update Node. js application on changes.
To run a script, open it in the editor or select it in the Project tool window, and then select Run <script file name> from the context menu. WebStorm creates a temporary run/debug configuration of the type Node. js. To run a test, click the gutter icon next to it or press Ctrl+Shift+F10 .
Problem is caused by weird dynamic way these chai methods are defined. As a workaround I can suggest using chai.d.ts:
Open "Settings | Languages & Frameworks | JavaScript | Libraries
"
Click "Download...
" button and select "TypeScript community stubs"
Find "chai" and click "Download and Install
".
See http://blog.jetbrains.com/webstorm/2014/07/how-webstorm-works-completion-for-javascript-libraries/, 'Using TypeScript community stubs (TypeScript definition files)' for more information
WebStorm 2020.1
TypeScript definitions can also be added directly via package.json:
For example:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With