mardi 29 mars 2016

Properly initialize $scope - having error : "Expected undefined to be defined"

I need help, been searching and thinking for hours but didn't come up with a good solution. I am experiencing error "Expected undefined to be defined" which is repeatedly occurs when I call $scope in my It() functions.

Spec.js

describe("C0001Controller", function(){



var $scope,
$rootScope,
$injector,
$controller,
$httpBackend,
$loading,
C0001Controller;


describe("initialize controllers",function(){

    beforeEach(function(){
        angular.module('app.c0001App');
    })



    beforeEach(inject(function(_$rootScope_, _$injector_, _$controller_, _$httpBackend_, _$loading_)
    {
        $rootScope = _$rootScope_;
        $injector = _$injector_;
        $controller = _$controller_;
        $httpBackend = _$httpBackend_;
        $loading = _$loading_;
        $scope = $rootScope;
        C0001Controller = $controller('C0001Controller', {
            $scope: $scope,
            $loading :  $loading

        });

    }));
});
    it("should use the user ",function(){
    var languages = [{id: "en", name: "English"}, {id: "jp", name: "Japanese"}];
    expect(languages).toBeDefined();

    it("should read if there are languages used", function(){
    expect($scope).toBeDefined();

});
        describe("checking connection to module and controller", function(){

    it("should be connected to module", function(){
        expect("app.c0001App.C0001Controller").toBeDefined();
    });

    it("contains C0001Spec Spec", function(){
        expect(true).toBe(true);
    });

    it("should be equal to user", function(){
        var user = {};
        var c0001Data =  user;
        expect(c0001Data).toBe(user);
    });

});
});

I was thinking if the format I did in the karma.conf.js file has a mistake.

// list of files / patterns to load in the browser
files: [

'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',

  'app/*.js',
  'tests/*.js'
],

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire