Skip to content

cowboyd/mocha-snippets.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocha Snippets

MELPA Build Status

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

Snippet Flavors

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) {

});

Snippets

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)

Customization

Mocha snippets have several configuration points to let your control how snippets are generated.

mocha-snippets-string-delimiter

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.
});

mocha-snippets-use-fat-arrows

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.
});

mocha-snippet-add-space-after-function-keyword

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.
})

About

An E-Lisp package containing helpful yasnippets for use with the Mocha JavaScript testing framework

Resources

Stars

Watchers

Forks

Packages

No packages published