You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote some tests using Mocha (see juandopazo@213ada3), but the issue is that since Task catches errors in the generator function there is no clear way to get Mocha to show the correct assertion failures.
Would you be interested in using YUI Test? It uses a resume() function for asynchronous tests that creates a new context to catch errors. Here's an example test:
'task should retrieve a promise\'s value': function(){vartest=this,expected='hello world';spawn(function(){varactual=yieldPromise.resolve(expected);test.resume(function(){Assert.areSame(expected,actual);});});test.wait();}
Another option could be Jasmine. Jasmine tests look very similar to Mocha, but they also provide their own context for assertions through a runs function. It ends up being a lot more code though. See:
it('task should retrieve a promise\'s value': function(){vardone=false;varsomeString='hello world';varvalue;runs(function(){spawn(function(){value=yieldPromise.resolve(someString);done=true;});});waitsFor(function(){returndone==true;});runs(function(){expect(value).to.eql(someString);});});
Activity
dherman commentedon Dec 22, 2011
Maybe mocha:
http://dailyjs.com/2011/12/08/mocha/
https://github.com/visionmedia/mocha
juandopazo commentedon Jun 2, 2013
I wrote some tests using Mocha (see juandopazo@213ada3), but the issue is that since Task catches errors in the generator function there is no clear way to get Mocha to show the correct assertion failures.
Would you be interested in using YUI Test? It uses a
resume()function for asynchronous tests that creates a new context to catch errors. Here's an example test:juandopazo commentedon Jun 4, 2013
Tests using YUI: juandopazo@bc26447.
Another option could be Jasmine. Jasmine tests look very similar to Mocha, but they also provide their own context for assertions through a
runsfunction. It ends up being a lot more code though. See:mbulman commentedon Jun 5, 2013
Fwiw, using doh (dojo's test harness) deferreds, the above test would look something like:
Disclaimer: I just happened to be following this thread, and haven't tested the above code at all.
juandopazo commentedon Jun 5, 2013
The problem with that version is that
spawnexpects a generator andgetTestCallbackreturns a callback.mbulman commentedon Jun 6, 2013
Oh right. Then without the convenience of
getTestCallback, it would look something like: