tldr; M-x package-install mocha-snippets
I like Mocha, and I use it a lot. As such, I have a bunch of snippets that I've developed for it to make working with tests faster.
It contains snippets for both coffee-mode
and js-mode
Snippets come in two flavors: synchronous and
explicitly asynchronous. To invoke the explicitly asynchronous
version of a snippet, append a .
after it. So for example, the bef
snippet expands to:
beforeEach(function() {
});
whereas the bef.
snippet will expand to:
beforEach(function(done) {
});
desc
-> describe block
cont
-> context block (alias for describe)
bef
-> beforeEach block
bef.
-> beforeEach block (async)
before
-> before block
before.
-> before block (async)
aft
-> afterEach block
aft.
-> afterEach block (async)
after
-> after block
after.
-> after block (async)
it
-> it block
it.
-> it block (async)
For both setup and teardown, the short forms bef
and aft
have
been given to beforeEach
and afterEach
respectively, since
those are more commonly used (and if they aren't, then perhaps they
shoud be)
Mocha snippets have several configuration points to let your control how snippets are generated.
By default, mocha snippets uses single quotes to delimit strings in
its templates. However, you can set this variable to either "
or
``` to use a different delimiter:
//desc=>
describe('something', function() {
//cursor here.
});
configure the varibale
(setq mocha-snippets-string-delimiter "\"")
and it now becomes:
//desc=>
describe("something", function() {
//cursor here.
});
Out of the box, mocha will use "classic" function syntax for all of the functions it generates for you. However, if you like to use ES6 fat arrow syntax, you can set this variable and your snippets will now all use it.
(setq mocha-snippets-use-fat-arrows t)
//desc=>
describe('something', ()=> {
//cursor here.
});
Some linting tools requires you to add a space after function
keyword. You have the option to customize it with
(setq mocha-snippets-add-space-after-function-keyword t)
//desc=>
describe('something', function () {
//cursor here.
});
//ES6
//desc=>
describe('something', () => {
//cursor here.
})