簡體   English   中英

ReferenceError:Jasmine Angular js中未定義模塊

[英]ReferenceError: module is not defined in Jasmine Angular js

我從Angular和單元測試開始,這是我的第一個代碼,但無法正常工作。 我在尋找解決方案,但我不知道自己在做什么錯。 如果有人可以向我解釋是什么錯誤,我將感謝您。

這就是我的全部代碼。

<!DOCTYPE html>
<html lang="en">

<head>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-mocks.js"></script>
<script src="jasmine.js"></script>
<script src="jasmine-html.js"></script>
<script src="boot.js"></script>
<link rel="shortcut icon" type="image/png" href="jasmine_favicon.png">
<link rel="stylesheet" href="jasmine.css">

</head>

<body  ng-app = "myApp">

<div ng-controller = "MyCtrl">
{{greeting}}
</div>
<br><br><br>

<script>

    <!-- CODE -->

    var myApp = angular.module('myApp',[]);

    myApp.controller('MyCtrl', ['$scope', function($scope) {
        $scope.greeting = 'Hello World!';
    }]);

    <!-- JASMINE -->

    describe('myApp', function () {
        var scope,
        controller;
        beforeEach(function () {
            module('myApp');
        });

        describe('MyCtrl', function () {
            beforeEach(inject(function ($rootScope, $controller) {
                scope = $rootScope.$new();
                controller = $controller('MyCtrl', {
                    '$scope': scope
                });
            }));
            it('sets the greeting', function () {
                expect(scope.greeting).toBe('Hello World!');
            });

        });
    });

    describe('JavaScript addition operator', function () {
        it('adds two numbers together', function () {
            expect(1 + 2).toEqual(3);
        });
    });
</script>

</body>

</html>

提前致謝

您的腳本順序錯誤。 您應該首先包含與Jasmine相關的腳本,然后包含有關角和角-的腳本。

<!DOCTYPE html>
<html lang="en">

<head>
<!--Scripts for Jasmine-->
<script src="jasmine.js"></script>
<script src="jasmine-html.js"></script>
<script src="boot.js"></script>

<!--Script for Angular-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>

<!--Scripts for Angular-Mocks-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-mocks.js"></script>
<link rel="shortcut icon" type="image/png" href="jasmine_favicon.png">
<link rel="stylesheet" href="jasmine.css">
</head>

<body  ng-app = "myApp">

<div ng-controller = "MyCtrl">
{{greeting}}
</div>
<br><br><br>

<script>

<!-- CODE -->

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', ['$scope', function($scope) {
    $scope.greeting = 'Hello World!';
}]);

<!-- JASMINE -->

describe('myApp', function () {
    var scope,
    controller;
    beforeEach(function () {
        module('myApp');
    });

    describe('MyCtrl', function () {
        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            controller = $controller('MyCtrl', {
                '$scope': scope
            });
        }));
        it('sets the greeting', function () {
            expect(scope.greeting).toBe('Hello World!');
        });

    });
});

describe('JavaScript addition operator', function () {
    it('adds two numbers together', function () {
        expect(1 + 2).toEqual(3);
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM