KarmaJS在afterAll方法中抛出只读错误

时间:2018-04-25 19:22:48

标签: angular phantomjs karma-jasmine

我有一个项目包含:

  • Angular 1.6.10
  • Jasmine 3.1.0
  • PhantomJS 2.2.1
  • Karma 2.0.2

我正在为以下课程创建单元测试:

'use strict';

angular.module('Core').controller('MainController', function() {

  var $this = {
    calculateBirthYear: function(age) {
      return (2018 - age);
    }
  };
  return $this;
});

测试js:

describe('Testing AngularJS Test Suite', function() {

  var MainController;

  beforeEach(module('Core'));
  beforeEach(inject( function ($controller) {
        MainController = $controller('MainController');
  }));


  it('should sum correctly the birth date', function() {
      console.log('Birth: %o',MainController.calculateBirthYear(18));
      expect(MainController.calculateBirthYear(18)).toBe(2000);
  });

});

当我查看日志时,它显示它正在计算但有错误,我不知道如何处理。

LOG: 'Birth: %o', 2000
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  {
    "message": "An error was thrown in afterAll\nTypeError: Attempted to assign to readonly property.",
    "str": "An error was thrown in afterAll\nTypeError: Attempted to assign to readonly property."
  }

0 个答案:

没有答案