【发布时间】:2023-03-25 18:40:01
【问题描述】:
试图访问这个 if 语句,但我的报道说我不是。有什么想法吗?提前致谢!
'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) {
【问题讨论】:
标签: javascript angularjs unit-testing jasmine code-coverage