vscode-jest
vscode-jest copied to clipboard
Add snippets
Any chance snippets could be added to this library? Some of the Jest methods are really long, and dropdowns for them don't appear for mocks.
So for instance, a snippet could be like this:
"mock implementation once": {
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"prefix": "mio",
"body": "${1:mock}.mockImplementationOnce($0)",
"description": "Mock implementation once",
}
This repo seems like a great spot for snippets. Are there any existing standards we should embrace?
Not sure about standards, but the snippets docs are a great place to start. Personally, I'd only need snippets for all the Jest mock functions (there are about 20 of them). The expect methods aren't needed, since VSC IntelliSense should already handle them.
And we don't want to pollute the snippets too much, otherwise they might start conflicting with other snippets that users already have installed. Maybe prefix each snippet with j
, so rather than mio
like in my example above, it could be jmio
. And then mockFn.mockClear()
could be jmc
instead, etc. Because a two-letter prefix is more likely to conflict with something else.
One thing that I notice snippet authors often exclude, is that they don't have $0
in the snippet, to denote the final cursor position. Personally I prefer if it's there though, especially for some types of snippets.
To include snippets in an extension, create a json
file containing them, then indicate their path with this. As seen here, it's recommended to apply the snippets to four languages: javascript
, javascriptreact
, typescript
, and typescriptreact
.
One big problem is that IntelliSense will not appear within snippets, so you can't use it to auto-fill the mockFn
value, unfortunately. And they sometimes have long names, etc. This default behavior can be changed with the editor.suggest.snippetsPreventQuickSuggestions
setting.
https://marketplace.visualstudio.com/items?itemName=andys8.jest-snippets :)