Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm - How to edit Jasmine code completion snippets

When writing Jasmine unit tests in WebStorm (11.0.2), using the Command + N (OS X) command gives me the following popup menu:

Generate

  • Jasmine Suite
  • Jasmine Spec
  • Jasmine beforeEach
  • Jasmine afterEach

I'd like to modify the code these menu items generate. For example, I'm using ES6, and would like to change the Jasmine Suite option to generate:

describe('suite name', () => {
});

Instead of:

describe('suite name', function () {
});

I'm digging through the WebStorm Preferences, but can't see any options to modify this. Any ideas?

like image 402
Brant Avatar asked Dec 28 '25 18:12

Brant


1 Answers

I still haven't found a way to edit the code template when using Command-N keyboard shortcut, but similar functionality can be found using a "Live Template", giving you complete control of the template.

Navigate to:

Preferences -> Editor -> Live Templates

Select the JavaScript option in the right pane, and then the + icon to add a template.

Configuration Values:

Abbreviation: desc

Description: Jasmine Suite

Template Text:

describe('$SUITE_DESC$', () => {
  $END$
});

Typing 'desc' then Tab, will generate the template. From there, you can add additional live templates for 'it', 'beforeEach' and 'afterEach', using the same approach.

like image 149
Brant Avatar answered Dec 31 '25 17:12

Brant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!