I need some help getting this test to run. I've spent way to much time on it.
So i am stuck and need some help?
I simply have a factory method, that has one method and i keep getting [Unable to get property 'method1' of undefined or null reference ] errors from Karma.
(function () {
'use strict';
var first = function () {
var method1 = function () {
return 'yes';
};
return {
method1: method1
};
};
angular.module('app').factory('first', [first]);
})();
and here are my attempts to call 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');
});
});
});
and my output from Karma
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)