anmatika
anmatika

Reputation: 1701

Testing AngularJS controller /w karma-jasmine: 'jasmine.clock().mockDate(baseTime)' undefined

Testing setup:
"karma-jasmine": "^0.2.3",
"karma-phantomjs-launcher": "^0.1.4",

The test:

'use strict';

describe('Controller: Ctrl', function () {

  // load the controller's module
  beforeEach(module('app'));

  var Ctrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    Ctrl = $controller('Ctrl', {
      $scope: scope
    });

    jasmine.clock().install();
  }));

  it('scope.<day> should be correct', function () {

    var baseTime = new Date(2014,10,24);
    jasmine.clock().mockDate(baseTime);

    expect(scope.sunday).toBe(false);
    expect(scope.monday).toBe(true);    
    expect(scope.tuesday).toBe(false);
    expect(scope.wednesday).toBe(false);
    expect(scope.thursday).toBe(false);
    expect(scope.friday).toBe(false);
    expect(scope.saturday).toBe(false);

  });
});

Gives this:

PhantomJS 1.9.8 (Linux) Controller: Ctrl scope. should be correct FAILED
TypeError: 'undefined' is not a function (evaluating 'jasmine.clock().mockDate(baseTime)')**

Upvotes: 1

Views: 1475

Answers (1)

hon2a
hon2a

Reputation: 7214

Use karma-jasmine version 0.3.x, which doesn't include jasmine on its own. Then specify the version of jasmine containing your required functionality.

Upvotes: 4

Related Questions