0
このifステートメントにアクセスしようとしましたが、私のカバレッジは私がそうではないと言っています。何かご意見は?前もって感謝します!ifステートメントのテスト - AngularJS/Jasmine
'use strict';
describe('Service: configService', function() {
// load the controller's module
beforeEach(module('Service'));
var configService, scope, httpBackend, results, tstConfigObj;
var tstConfig = {
"confLocation": "local-dev-conf.json"
};
// Initialize the controller and a mock scope
beforeEach(inject(function(_configService_, $httpBackend, $rootScope) {
scope = $rootScope.$new();
configService = _configService_;
httpBackend = $httpBackend;
// $rootScope.configObj = tstConfigObj;
spyOn(configService, 'getConfig').and.callThrough();
httpBackend.when('GET', 'conf.json').respond(200, tstConfig);
httpBackend.when('GET', 'local-dev-conf.json').respond(200, {});
}));
describe('Function getConfig():', function() {
it('should check if it was called', inject(function() {
configService.getConfig();
httpBackend.flush();
expect(configService.getConfig).toHaveBeenCalled();
}));
it('should check if statement', inject(function() {
scope.configObj = "Tesla is awesome";
results = scope.configObj;
configService.getConfig();
httpBackend.flush();
expect(results).not.toBe(null);
}));
console.log(results);
});
});
私はconfigObj != null
を作成する必要がありますが、そうするのに苦労。私の範囲が間違っているかもしれない?
EDIT:機能にconfigObj
を渡すことによって修正:ここ
getConfig: function(configObj) {
お返事ありがとうございます。私はあなたが直接上にあるreturn文の後にconfigObjを定義することを意味すると思いますか?もしそうなら、それは残念ながらエラーを投げます – FF5Ninja
これは動作しませんか? 'return { configObj:null、 //あなたの他のコード' – Jelle