我需要一些帮助才能运行此测试。我花了很多时间在它上面。
所以我被困住了,需要一些帮助吗?
我只是有一个工厂方法,它有一个方法,并且我不断收到来自 Karma 的 [Unable to get property 'method1' of undefined or null reference ] 错误。
(function () {
'use strict';
var first = function () {
var method1 = function () {
return 'yes';
};
return {
method1: method1
};
};
angular.module('app').factory('first', [first]);
})();
这是我尝试调用method1的尝试。
describe('Test Suite', function () {
describe('Factory Test', function () {
beforeEach(function () {
module('app');
});
var service;
//beforeEach(inject(function (_first_) {
// service = _first_;
// console.log(JSON.stringify(_first_, null, 4));
//}));
beforeEach(inject(function ($injector) {
service = $injector.get('first');
console.log(JSON.stringify(service, null, 4));
}));
//beforeEach(function () {
// angular.mock.inject(function ($injector) {
// service = $injector.get('first');
// })
//});
describe('calling method1', function () {
var output = service.method1();
expect(output).toBe('yes');
});
});
});
和我从业力的输出
IE 11.0.0 (Windows 10 0.0.0) Test Suite Factory Test calling method1 encountered a declaration exception FAILED
TypeError: Unable to get property 'method1' of undefined or null reference
at Anonymous function (tests/firstTest.spec.js:31:13)
at Anonymous function (tests/firstTest.spec.js:30:9)
at Anonymous function (tests/firstTest.spec.js:4:5)
IE 11.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.135 secs)
IE 11.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.14 secs / 0.135 secs)