Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正确初始化$scope-出现错误:“0”;“预期未定义待定义”;_Javascript_Angularjs_Unit Testing_Jasmine_Karma Jasmine - Fatal编程技术网

Javascript 正确初始化$scope-出现错误:“0”;“预期未定义待定义”;

Javascript 正确初始化$scope-出现错误:“0”;“预期未定义待定义”;,javascript,angularjs,unit-testing,jasmine,karma-jasmine,Javascript,Angularjs,Unit Testing,Jasmine,Karma Jasmine,我需要帮助,搜索和思考了几个小时,但没有找到一个好的解决方案。我遇到错误“预期未定义要定义”,当我在It()函数中调用$scope时,会重复出现该错误 Spec.js describe("C0001Controller", function(){ var $scope, $rootScope, $injector, $controller, $httpBackend, $loading, C0001Controller; describe("initialize controllers

我需要帮助,搜索和思考了几个小时,但没有找到一个好的解决方案。我遇到错误
“预期未定义要定义”
,当我在It()函数中调用$scope时,会重复出现该错误

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);
    });

});
});
angular.module('app.c0001App', [
'ui.router'
])
 .config(function($stateProvider) {
  $stateProvider.state('/c0001', {
  url         : '/c0001'
, templateUrl : 'pages/C0001.html'
, data        : {
                 pageTitle: 'LOGIN'
                }
  });
   })
.controller('C0001Controller', function ($rootScope, $scope, $http, $window,        $location, $loading) {

var promise = $http.get('changeLanguage.do?lang=en');
promise.success(function(data, status, headers, config) {
//some codes here
我在想我在karma.conf.js文件中使用的格式是否有错误

// 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'
],
这是我的Controller.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);
    });

});
});
angular.module('app.c0001App', [
'ui.router'
])
 .config(function($stateProvider) {
  $stateProvider.state('/c0001', {
  url         : '/c0001'
, templateUrl : 'pages/C0001.html'
, data        : {
                 pageTitle: 'LOGIN'
                }
  });
   })
.controller('C0001Controller', function ($rootScope, $scope, $http, $window,        $location, $loading) {

var promise = $http.get('changeLanguage.do?lang=en');
promise.success(function(data, status, headers, config) {
//some codes here

提前谢谢。

您有3个expect.toBeDefined,具体哪一行出错了?我编辑了我的答案,实际上那些使用$scope的it()函数给出了错误,我不知道哪里出了问题,因为我是Jasmine测试的新手。我在这一部分有错误:它(“如果使用了语言,则应读取”,function(){expect($scope).toBeDefined();我想它不会与我的控制器交互,有人说karma.conf.js中的声明模块有问题。你的spec.js有很多问题。我建议你看看。使用示例代码,从一个测试开始。试试这个,如果你还需要帮助,请告诉我。