Jasmine and Angularjs error

Jasmine and Angularjs error

本文关键字:error Angularjs and Jasmine      更新时间:2023-09-26

我想在AngularJS $作用域上做一个简单的测试。我已经遵循了多个教程,但不断得到一个错误。一直显示的错误是:

"模块'onePortal'不可用!您可能拼写了模块名,或者忘记加载它。如果注册一个模块,请确保将依赖项指定为第二个参数。

我的控制器代码看起来像:

var app = angular.module('onePortal', []);
app.controller('indexController', function($scope) {
    $scope.text = 'Hello World!';
});

我的测试代码如下:

    'use strict';
    describe('indexController', function() {
      var scope;
      beforeEach(angular.mock.module('onePortal'));
      beforeEach(angular.mock.inject(function($rootScope, $controller) {
        scope = $rootScope.$new();
        $controller('indexController', {$scope: scope});
      }));
      it('should have variable test = "Hello World!"', function() {
        expect(scope.text).toBe('Hello World!');
      });
   });

有人知道为什么我总是得到这个错误吗?

确定您在茉莉测试html中包含包含应用程序声明的脚本?