Skip to content

Instantly share code, notes, and snippets.

@ahirschberg
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save ahirschberg/21d5f409adf1e8127a06 to your computer and use it in GitHub Desktop.

Select an option

Save ahirschberg/21d5f409adf1e8127a06 to your computer and use it in GitHub Desktop.
Abbreviated version of book player page generation tests
describe('BookPlayerPageGenerator()', function () {
var bppg, dlManager, dlManagerMock;
before(function () {
// ... (omitted) set up audio and button elements and append them to body ...
// Set up a dummy object with a stubbed BookDownloadManager interface
dlManager = { downloadBook: function (book_id, chapter_obj) {},
downloadChapter: function (book_obj) {} };
dlManagerMock = sinon.mock(dlManager); // setup a mock of the dlManager object
// dlManager, NOT dlManagerMock, passed in args
bookPlayerArgs = {/* other args omitted, */ 'bookDownloadManager': dlManager };
bppg = new BookPlayerPageGenerator(bookPlayerArgs);
});
describe('#generatePage()', function () {
it('adds onclick to the book download DOM element', function () {
bppg.generatePage(/* ... args */); // run method
dlManagerMock.expects("downloadBook").once().withExactArgs(BOOK_OBJECT); // set up expectations for mock
$('#downloadBook').trigger('click'); // should call dlManager's #downloadBook() method matching expectations
dlManagerMock.verify(); // verify that #downloadBook() has been called or fail if it hasn't
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment