javascript - Angular 单元测试 : Browser is not defined?

标签 javascript testing angularjs scenarios angular-scenario

我正在 Angular 应用程序的 Controller 上运行单元测试。到目前为止我的测试是:

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

带 Controller

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

最佳答案

我修好了。我添加了行

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

等等你需要的其他路径。

关于javascript - Angular 单元测试 : Browser is not defined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17050755/

相关文章:

javascript - 将较少生成的 css 应用于除 th 元素之外的所有 html 表

javascript - 如何在 Jasmine 中测试函数表达式

unit-testing - 部署一个伪装成程序的大测试

jquery - 如何判断导航栏是否折叠以切换导航栏列表中的元素

angularjs - 如何将 Angular 2 与 NetBeans 一起使用?

javascript - 2 "onmouseover"破坏页面的工作

javascript - spyOn 找不到要监视 start() 的对象

javascript - 在 React 中从父组件到子组件共享状态

php - Yii2 扩展开发测试环境指南

javascript - 在 Angular Directive(指令)中提交表单