Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2012 10:44
What would you like to do?
Model Fetch Unit Test
describe("A Model should", function() {
describe( "have a fetch method that", function() {
beforeEach(function() {
urls = ['url1', 'url2', 'url3', 'url4', 'url5']
spyOn( $, 'ajax');
it( "makes an AJAX request for each URL it is passed", function() {
model.fetch( urls );
expect( $.ajax ).toHaveBeenCalled();
expect( $.ajax.callCount ).toEqual( urls.length )
Copy link

It looks good. Here’s my take:

describe("Model", function() {
  describe("fetch", function() {
    beforeEach(function() {
      urls = ['url1', 'url2', 'url3', 'url4', 'url5'];
      spyOn($, 'ajax');
    describe("with parameter Array", function () {
      it("calls $.ajax for each URL in the Array", function() {



  • Descriptions should be short and tied to the class/method names
  • Let the descriptions make comments redundant Uncle Bob
  • Use semi-colons consistently
  • Make one expectation per spec


  • Using callCount makes the expectation that $.ajax was called redundant

Interested to hear others’ thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment