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
describe('article',function(){it('show all gist',function(done){vargists=[{html_url:"https://gist.github.com/2171fd506edc072ca80e"}];vargistsData=Q(gists);getGists=stub().returns(gistsData);renderGist();gistsData.should.be.fulfilled.then(function(){nunjucks.render.calledOnce.should.be.true;nunjucks.render.getCall(0).args[0].should.be.equal("src/templates/gistlist.html");nunjucks.render.getCall(0).args[1].should.be.deep.equal({gists:gists});}).should.notify(done);});});
the .should.be.fulfilled.then and notify is provide by chai promise plugin.
this test will check
if the getGists is been called
the Promise it returned should be fulfilled.
nunjucks.render has been called
nunjucks.render has been called with the right data.
finally notify the done callback provide by mocha, which tell moche the test has been done.
BTW change the before and after to beforeEach, why
get data and render is async, make sure bind event after render.
TASK 2 Walkthrough
Cross Domain Ajax
$.getJSON($(this).data("url")+".json?callback=?"
use getJSON and add callback=? to get JSONP across origin
bind event
your code will may like this:
getGists().then(function(body){$('.container .article').html(nunjucks.render("src/templates/gistlist.html",{gists:body}));}).then(bindEvent);functionbindEvent(){$(".article li a").click(function(){$.getJSON($(this).data("url")+".json?callback=?",function(data){$(".article").html(data.div);});});}renderHeader().then(renderGist);