Given When Then for mocha
mocha-gwt is a proud rewrite of mocha-given, which is a shameless port of Justin Searls' jasmine-given. As everyone of course knows,
jasmine-given is a shameless tribute to Jim Weirichs' terrific rspec-given gem
jasmine-given. In time I will most likely write documentation for this myself.
I have been using jasmine and
jasmine-given for a while but I found myself more and more favouring mocha over jasmine. I find mocha to be a more mature test runner and it seems to have greater performance. I was also bothered by some bugs in
jasmine-given and mocha-given. Furthermore I wanted to utalize the promise support that exists in mocha. After looking at the code, and figuring out by hand how to write mocha interfaces, I came to the conclusion that a complete re-write where I had full fredom to experiment was the best solution. I now believe that I was right.
When -> Promise.resolve('foo').then (@result) =>will make
@resultavailable in the following
describe 'myFunction', ->When -> @result = myFunction @inputInvariant -> @result == ''describe 'should return an empty string for undefined input'Given -> @input = ''describe 'should return an empty string for null input'Given -> @input = null
Thenfunctions in the same describe will act just like
And...I.e it will not rerun the
Whenfunctions that belong to the suite. This might be changed to follow the standard. But I have myself never encountered a test where non-repetition was not the desire.
npm i -D mocha-gwt
mocha --ui mocha-gwt
mocha --ui mocha-gwt --require coffee-script --compilers coffee:coffee-script/register