2016-06-20 11 views
0

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?

Hier ist meine Abdeckung: coverage

EDIT: Fest von configObj in der Funktion übergeben:

getConfig: function(configObj) {

Antwort

0

Ihre configObj lokale Variable ist, also wenn Sie scope.configObj = "Something" nennen es wird nicht die Variable ändern du willst dich ändern. Versuchen Sie, es als Variable in die return-Anweisung einzufügen.

+0

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

+0

Funktioniert das nicht? 'return { configObj: null, // Ihr anderer Code' – Jelle