1

angularアプリのコントローラーで単体テストを実行しています。これまでの私のテストは次のとおりです。

describe('Controller', function () {
    var scope, ctrl;
    beforeEach(module('myApp'));
    beforeEach(inject(function ($rootScope,
                                $controller) {
        scope = $rootScope.$new();
        ctrl = $controller('Controller', {
            $scope: scope
        });
    }));
    beforeEach(browser().navigateTo('/'));
    it('should get you to the next page', function () {
        scope.submit();
        expect(browser().location().path()).toBe('/new')
    });
});

コントローラー付き

var Controller = function ($scope, $location) {
    $scope.submit = function () {
        $location.path('/new');
    }
}

ただし、これを実行するとエラーが発生しますbrowser is not defined。ここで何が起こっているのですか?これはAngularによって提供されていませんか?

編集:さらに奇妙なことに、inject定義されていないエラーが発生しています。

設定ファイルは次のとおりです。

basePath = '../';

framework = ["ng-scenario"];

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'http://code.jquery.com/jquery-1.9.1.min.js',
  'https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js',
  '../static/javascript/angular-mocks.js',
  '../static/javascript/angular-scenario.js',
  '../static/javascript/stripe.js',
  'templates/static/avgrund.jquery.js',
  'templates/static/chosen.jquery.js',
  'templates/static/app.js',
  'tests/E2E/tests.js'
];

urlRoot = '/_karma_/';

singleRun = true;

browsers = ['Chrome'];

junitReporter = {
  outputFile: 'test-output.xml',
  suite: 'e2e'
};
4

2 に答える 2

0

それを私が直した。行を追加しました

proxies = {
    '/static/': 'http://localhost:5000/static/'
}

必要な他のパスについても同様です。

于 2013-06-15T20:55:53.530 に答える
0

はい。シナリオ ランナーは、http または https を使用して実行する必要があります。または、別の html で e2e を実行することもできます。形式は次のようになります。

<html lang="en">
<head>
<title>End2end Test Runner</title>
<meta charset="utf-8">
<base href="../..">
<script src="app/lib/angular/angular-scenario.js" ng-autotest></script>
<script src="test/e2e/scenarios.js"></script>
</head>
<body>
</body>
</html>

注意、このファイル「angular-scenario.js」を参照する必要があります

于 2014-03-07T06:29:28.253 に答える