Created
November 29, 2012 18:48
-
-
Save pamelafox/4171071 to your computer and use it in GitHub Desktop.
Coursera catalog view test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('catalogyBody', function() { | |
var chai = require('chai'); | |
var path = require('path'); | |
var env = require(path.join(testDir, 'lib', 'environment')); | |
var requirejs = env.requirejs(staticDir); | |
var sinon = requirejs('js/lib/sinon'); | |
var fs = require('fs'); | |
var server; | |
var router; | |
describe('catalog list', function(){ | |
beforeEach(function() { | |
server = sinon.fakeServer.create(); | |
// Coursera.router.navigate will never work because history/routes haven't been set up | |
// mock these calls when a view needs them, so tests do not block | |
router = sinon.stub(Coursera.router, 'navigate', function() { }); | |
}); | |
afterEach(function() { | |
server.restore(); | |
router.restore(); | |
}); | |
var courses = fs.readFileSync(path.join(__filename, '../../data/courses/courses.json'), 'utf-8'); | |
var Coursera = requirejs('js/app/home'); | |
var catalogBody = requirejs('pages/home/catalog/catalogBody'); | |
it('should render the catalog', function(done) { | |
server.respondWith("GET", Coursera.config.url.api + "topic/list?full=1", | |
[200, {"Content-Type":"application/json"}, courses]); | |
var view = new catalogBody(); | |
// render does an ajax call which calls renderTopics, so we need | |
// to stub it, so we can catch the ajax return call, and then call renderTopics manually | |
var renderTopics = sinon.stub(view, 'renderTopics', function() { | |
renderTopics.restore(); | |
view.renderTopics.apply(view, arguments); | |
chai.expect(view.$('.coursera-catalog-course-listing-box').size()).to.be.equal(10); | |
done(); | |
}); | |
view.render(); | |
server.respond(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment