Reputation: 50272
In Webstorm, I'm using jest for unit tests, and have created an extension using expect.extend()
. The code for this is in {projectDir}./tests/jest-helpers.js
and in my package.json
I have the following:
"jest": {
"setupFilesAfterEnv": ["./tests/jest-helpers.js"]
}
This is working great, and the expect
extension is working great in my unit tests. However, the code calling this method in my unit tests is not being recognized as valid, with a warning hint "Unresolved function or method."
I added the .js file as a Library, but this still didn't do the job. How do I get the method to be recognized? Is there some JSDoc thing I can do that will tell WebStorm that the expect
object has a new property?
Example of my expect
extension definition that isn't being picked up as a valid method.
// jest-helper.js
expect.extend({
toSmellLike(actual, expected) {
// an implementation
}
});
In use:
expect(value).toSmellLike('bananas'); // `toSmellLike is highlighted with a warning
Upvotes: 3
Views: 347
Reputation: 426
I was looking for the same....the best I got was to use JSDoc comment to get custom method highlighted.
/**
* @typedef {jest.Expect} expect
* @property {function} toSmellLike
*/
Just add this above your extend call and it should work.
Still looking how to get code completion working with it.
Upvotes: 0