Der Versuch, auf diese if-Anweisung zuzugreifen, aber meine Berichterstattung sagt, dass ich es nicht bin. Irgendwelche Gedanken? Danke im Voraus!Eine if-Anweisung testen - 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);
});
});
Ich brauche configObj != null
zu machen, aber zu kämpfen, dies zu tun. Irgendetwas stimmt nicht mit meinem Zielfernrohr?
EDIT: Fest von configObj
in der Funktion übergeben:
getConfig: function(configObj) {
Hey, danke für die Antwort. Ich nehme an, Sie meinen configObj nach der Return-Anweisung zu definieren, die direkt darüber liegt? Wenn ja, wirft es leider einen Fehler – FF5Ninja
Funktioniert das nicht? 'return { configObj: null, // Ihr anderer Code' – Jelle