未捕获错误:[$ injector:nomod]模块' app'不可用

时间:2017-11-24 23:41:35

标签: angularjs karma-jasmine

我是angularjs的新手,我在使用karma-jasmine进行测试时遇到此错误

未捕捉错误:[$ injector:nomod]模块' app'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。   http://errors.angularjs.org/1.6.6/ $注射器/ NOMOD?P0 =应用   在bower_components / angular / angular.js:2297

TypeError: descriptor 'replace' requires a 'str' object but received a 'SelectorList'

这是我的app.js

describe('LoginController', function () {

beforeEach(module('app'));

var $controller;

beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));

describe('homeBtn', function () {
    it('whether its sign in or register', function () {
        var $scope = {};
        var controller = $controller('LoginController', { $scope: $scope });

        $scope.homeBtn("Register");
        expect($scope.signinerror).toBeFalsy();
        expect($scope.tryagain).toBeFalsy();
        expect($scope.registererror).toBeFalsy();
        expect($scope.modal_title).toBe("Register");
    }); 
});

});

这是我的登录控制器

var app = angular.module('app', ['ngRoute','ngWebSocket','ng.epoch']);

这是我的HTML代码

angular.module('app').controller('LoginController',['$rootScope','$scope','$location','$http', function($rootScope,$scope,$location,$http){
$scope.homeBtn = function(keyvalue){
    $scope.signinerror=false;
    $scope.tryagain=false;
    $scope.registererror=false;

    if(keyvalue == "Register"){

        $scope.modal_title="Register";
        $scope.reg=true;
    }
    else{
        $scope.reg=false;
        $scope.modal_title="Sign In";
    }
}

这是我的业力配置文件

 <!DOCTYPE html>
<html ng-app="app">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <link rel="stylesheet"href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="bower_components/epoch/dist/css/epoch.min.css">

    <link rel="stylesheet" href="app/css/index.css">

</head>
<body>
    <ng-view> </ng-view>    
    <!--Bower Components-->
        <script src="bower_components/jquery/dist/jquery.min.js"></script>
        <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
        <script src="bower_components/angular/angular.js"></script>
        <script src="bower_components/angular-route/angular-route.min.js"></script>
        <script src="bower_components/angular-websocket/dist/angular-websocket.min.js"></script>
        <script src="bower_components/d3/d3.js"></script>
        <script src="bower_components/epoch/dist/js/epoch.min.js"></script>
        <script src="bower_components/ng-epoch/ng-epoch.js"></script>
        <script src="bower_components/js-md5/src/md5.js"></script>

    <!--MainJS-->
         <script src="app/js/app.js"></script>


        <!--Controllers-->
        <script src="app/js/Controllers/LoginController.js"></script>
        <script src="app/js/Controllers/HomeController.js"></script>


        <!--custom js files-->

        <script src="app/js/libraries/common.js"></script>
        <script src="app/js/libraries/smoothie.js"></script>
        <!--directives-->


        <!--factories-->
        <script src="app/js/Factories/websocketservice.js"></script>
    </body>
</html>

0 个答案:

没有答案