0

After fixing alot of erros in the testing, now Karma output is this:

PhantomJS 1.9.8 (Windows 8 0.0.0) Controller: MainCtrl should attach a list of t hings to the scope FAILED
Error: Unexpected request: GET /api/marcas No more request expected at ....

api/marcas is an endpoint i've created. code for MainCtrl:

'use strict';

angular.module('app')
.controller('MainCtrl', function ($scope, $http, $log, socket, $location, $rootScope) {
    window.scope = $scope;
    window.rootscope = $rootScope
    $scope.awesomeThings = [];
    $scope.things = ["1", "2", "3"];



    $http.get('/api/things').success(function(awesomeThings) {
        $scope.awesomeThings = awesomeThings;
        socket.syncUpdates('thing', $scope.awesomeThings);
    });


    $scope.addThing = function() {   
        if($scope.newThing === '') {
            return;
        }


        $http.post('/api/things', { name: $scope.newThing });
        $scope.newThing = '';
    };

    $scope.deleteThing = function(thing) {
        $http.delete('/api/things/' + thing._id);
    };

    $scope.$on('$destroy', function () {
        socket.unsyncUpdates('thing');


    });



    $http.get('/api/marcas').success(function(marcas) {
        $scope.marcas = marcas;
        socket.syncUpdates('marcas', $scope.response);

        $scope.marcasArr = [];

        $scope.response.forEach(function(value) {
            $scope.marcas.push(value.name);
        });

        $scope.marcaSel = function() {
            for (i = 0; i < $scope.response.length; i++) {
                if ($scope.selectedMarca == $scope.response[i].name) {
                    $scope.modelos = $scope.response[i].modelos;
                };
            };      
        };



    });

1 Answers1

0

until you didn't posted your test-code, I guess that your test doesn't includes the following code:

beforeEach(inject(function () {
    httpBackend.expectGET('/api/marcas').respond(function(){
        return {/*some status code*/, {/*some data*/}, {/*any headers*/}};
    });
}));

if the karma-runner tries to execute your test-code, there are to get-requests to the $http-service, $http.get('/api/marcas') and $http.get('/api/things'). if one of these backend calls is not expected, karma cannot run the testcode successfully.

if you don't want to do special stuff for each but only return a default with success code for both calls, you can write so:

beforeEach(inject(function () {
    httpBackend.expectGET(/api/i).respond(function(){
        return {/*some status code*/, {/*some data*/}, {/*any headers*/}};
    });
}));
Anke Wenz
  • 425
  • 6
  • 9