我有一个项目包含:
我正在为以下课程创建单元测试:
'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."
}