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
,但努力這樣做。我的範圍有問題嗎?
編輯:在函數傳遞configObj
修正:
getConfig: function(configObj) {
嘿,謝謝你的回覆。我假設你是指在直接在上面的return語句之後定義configObj?如果是這樣,不幸的是會拋出一個錯誤 – FF5Ninja
這是行不通的? 'return { configObj:null, // your your other code' – Jelle