Sunday, August 9, 2015

WebStorm by JetBrains and chai assertion library code warnings easy adjustment

A technically oriented post today.

Re:  Webstorm undefined function or method warnings when using the chai assertion library for javascript and nodejs.

I spent some time recently working on a new nodejs module (meta-confirm)  and wanted to share a few bits of information I learned in the process as a result of hours of searching and experimentation.

I'm just giving back to the community for the next person who is struggling to find a quick, easy answer to this situation.

The problem: While creating a test using chai assertions, you get the message "Undefined function or method  x() ". In this example: " Undefined function or method contain()".

Undefined function or method contain()

The same issue exists for many of the assertions (not just .contain)

To fix this code completion warning in Webstorm 10....

  • Files  - Settings  - Languages and Frameworks  - Javascript - Libraries

  • Download


  • Change the drop selection from Official Libraries to Typescript Community Stubs

 Official Libraries

Typescript community stubs

  • Find chai and select Download and Install

  • Enable chai-DefinitelyTyped 

  • Now, your code checking in Webstorm will recognize the syntax of the chai expectation library.

Notice that the .contain no longer shows as an undefined function or method warning.

Mike Caspar
Passionate About Agile


chai assertion library
chai TypeScript community stub
WebStorm from JetBrains

No comments :

Post a Comment